Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA PROJECT (PLEASE SHOW SOLUTION) Create a NetBeans project for this activity. Consider the following code. Create a file, name it anything you want and

JAVA PROJECT (PLEASE SHOW SOLUTION)

  • Create a NetBeans project for this activity.

Consider the following code. Create a file, name it anything you want and paste the directory on the section of the code.

import java.io.*;

public class FileIOExercise {

public static void main(String args[]){

FileInputStream fileInputStream = null;

FileOutputStream fileOutputStream = null;

try {

fileInputStream = new FileInputStream();

fileOutputStream = new FileOutputStream("output.txt");

int c;

while ((c = in.read()) != -1) {

out.write(c);

}

}finally {

if (fileInputStream != null) {

fileInputStream.close();

}

if (fileOutputStream != null) {

fileOutputStream.close();

}

}

}

}

Test Stem / Question

Choices

1: Try to compile the code. What is wrong with it?

A: There is compile error because of unreported exception.

B: There is a syntax error.

C: Compile error because of streams cant be used this way.

D: run perfectly

2: Try to fix the error. What should you do?

A: Catch the exception or declare a throw statement.

B: Rename the local variables.

C: Remove the close statement of the fileOutputStream. Only input streams need to be closed.

D: Nothing

3: What exceptions do you need to catch or throw when dealing with Java IO?

  1. FileNotFoundException
  2. IOException
  3. InterruptedIOException

A: A, B & C

B: Only A & B

C: A Only

D: B only

4: Now that you have compiled and run the code? What happened?

A: The context of my input is copied from the output.txt

B: There a file not found exception since I did not define a output.txt directory.

C: Did not copy my input but no exception was thrown.

D: Compiler error.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. Define communication.

Answered: 1 week ago