logo

APSU Notes


Quiz 8

Question 1

Data in a file remains after program execution ends.

True

Question 2

A statement opening a text file for reading or writing may generate a FileNotFoundException.

True

Question 3

Which of the following is the correct way to open a text file called “myfile.txt” for reading?

1
inputStream = new Scanner(new File("myfile.txt"));

Question 4

Which Java class is the preferred class to use for reading from a text file?

Scanner

Question 5

Which of the following is not a method of the File class?

1
close()

Question 6

What is the difference between a full path name and a relative path name?

A full path name starts at the root directory while a relative path name starts at the directory in which the program is running.

Question 7

Which Java class is the preferred class to use for writing to a text file?

PrintWriter

Question 8

Which of the following statements opens a text file called “myfile.txt” so that new text can be appended to the existing contents of the file?

1
outputStream = new PrintWriter(new FileOutputStream("myfile.txt", true));

Question 9:

The close method of the PrintWriter class must be called inside of a try block.

False

Question 10

What is the difference between an input stream and an output stream?

An input stream reads data from a file or console and sends it to a program. An output stream takes data from a program and writes it to a file or console.

Question 11

What is the difference between a text file and a binary file?

A text file stores a sequence of characters while a binary file uses some other encoding of data.

Question 12

A comma-separated values or CSV file is a simple text format used to store a list of records.

True

Notes

Chapter 4/Streams