Question: Examine the following file processing program. import java.io.File; import java.io.PrintWriter; public class TextFile { public static void main(String[] args ) throws Exception { // associate

Examine the following file processing program.

import java.io.File;

import java.io.PrintWriter;

public class TextFile {

public static void main(String[] args) throws Exception {

// associate a file with a file object

File fileExample = new File("data.txt");

// associate the file with a PrintWriter object

PrintWriter pwInput = new PrintWriter(fileExample);

// write string data to the file

pwInput.println("Sammy Student");

// write string data to the file

pwInput.println("Engineer");

// write a double - precision number to the file

pwInput.println(35.50);

// write a Boolean value to the file

pwInput.print(true);

// de - allocate the PrintWriter object memory

pwInput.close();

// inform user that the file has been created

System.out.println("The data file has been created!");

}

}

Concerning the aforementioned program code, select the correct answer.

(1) The pWriter object is associated with the file named data.txt .

(a) True (b) False

(2) The println() method is used to write different data types to the file.

(a) True (b) False

(3) throws Exception is necessary to include in the program to prevent an unhandled exception type FileNotFoundException.

(a) True (b) False

(4) When the program is executed, only three lines of data are written to the text file.

(a) True (b) False

(5) The statement pwInput.close(); is executed before the data is written to the file.

(a) True (b) False

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!