Chapter 17 How is I/O Handled in Java

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

To append data to an existing file, use _____________ to construct a FileOutputStream for file out.dat.

new FileOutputStream("out.dat", true)

Which of the following is the legal mode for creating a new RandomAccessFile stream?

"rw"

After the following program is finished, how many bytes are written to the file t.dat? public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream( new FileOutputStream("t.dat")); output.writeChar('A'); output.close();

2 bytes.

After the following program is finished, how many bytes are written to the file t.dat? public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream( new FileOutputStream("t.dat")); output.writeShort(1234); output.writeShort(5678); output.close(); }}

4 bytes.

After the following program is finished, how many bytes are written to the file t.dat? public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream( new FileOutputStream("t.dat")); output.writeUTFString("ABCD"); output.close();

6 bytes.

After the following program is finished, how many bytes are written to the file t.dat? public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream( new FileOutputStream("t.dat")); output.writeChars("ABCD"); output.close();

8 bytes.

Which of the following statements are true?

A. A File object encapsulates the properties of a file or a path, but does not contain the methods for reading/writing. B. You can use the PrintWriter class for outputting text to a file. C. You can use the Scanner class for reading text from a file. D. An input object is also called an input stream. E. An output object is also called an output stream.

Which of the following statements are true?

A. All files are stored in binary format. So, all files are essentially binary files. B. Text I/O is built upon binary I/O to provide a level of abstraction for character encoding and decoding. C. Encoding and decoding are automatically performed by text I/O. D. For binary input, you need to know exactly how data were written in order to read them in correct type and order.

To create a file, you can use __________.

A. FileOutputStream B. FileWriter C. RandomAccessFile

Which of the following statements are true?

A. ObjectInputStream/ObjectOutputStream enables you to perform I/O for objects in addition for primitive type values and strings. B. Since ObjectInputStream/ObjectOutputStream contains all the functions of DataInputStream/DataOutputStream, you can replace DataInputStream/DataOutputStream completely by ObjectInputStream/ObjectOutputStream. C. To write an object, the object must be serializable. D. The Serializable interface does not contain any methods. So it is a mark interface. E. If all the elements in an array is serializable, the array is serializable too.

Which of the following statements are true?

A. Text I/O is built upon binary I/O to provide a level of abstraction for character encoding and decoding. B. Text I/O involves encoding and decoding. C. Binary I/O does not require conversions. D. Binary I/O is more efficient than text I/O, because binary I/O does not require encoding and decoding. E. Binary files are independent of the encoding scheme on the host machine and thus are portable.

The Loan class given in the text does not implement java.io.Serializable. Analyze the following code. public class Foo implements java.io.Serializable { private int v1; private static double v2; private Loan v3 = new Loan();

B. An instance of Foo cannot be serialized because Foo contains a non-serializable instance variable v3. C. If you mark v3 as transient, an instance of Foo is serializable.

Which of the following statements is not true?

D. The methods in an object are serialized.

Which of the following statements is correct to create a DataOutputStream to write to a file named out.dat?

DataOutputStream outfile = new DataOutputStream(new FileOutputStream("out.dat"));

What does the following code do? FileInputStream fis = new FileInputStream("test.dat");

E. It creates a FileInputStream for test.dat if test.dat exists.

Which type of exception occurs when creating a DataInputStream for a nonexistent file?

FileNotExist

What does the following code do? FileInputStream fis = new FileInputStream("test.dat");

It creates a FileInputStream for test.dat if test.dat exists.

With which I/O class can you append or update a file?

RandomAccessFile(),

Which method can you use to find out the number of the bytes in a file using InputStream?

available()

skip

skip


Kaugnay na mga set ng pag-aaral

Chapter 12 Comparative Labor Relations, Chapter 13 - What Should Labor Relations Do?, Chapter 10 Flexibility, Empowerment, and Partnership, Chapter 11- Globalization, final written responses

View Set

AP Psych review questions Unit 7

View Set

OB - chapter 19 Nursing Management of Pregnancy at Risk: Pregnancy-Related Complications

View Set

Unit 5 Test Review- World History Kratz

View Set

Chapter 28 The Complete Health Assessment: Adult

View Set

Ch. 29 Abdominal and Genitourinary Injuries

View Set

Processual and Post-Processual Archaeology, Theories

View Set