A file is created with the following code:
1. FileOutputStream fos = new FileOutputStream("datafile"); 2. DataOutputStream dos = new DataOutputStream(fos); 3. for (int i=0; i<500; i++) 4. dos.writeInt(i);
You would like to write code to read back the data from this file.
Which solutions will work?
Choose all that apply.
readInt()
method. readInt()
method. readInt()
method. readInt()
method. readInt()
method. A, D.
Option A chains a data input stream onto a file input stream.
D simply uses the RandomAccessFile class.
B fails because the FileReader class has no readInt()
method; readers and writers handle only text.
C fails because the PipedInputStream class has nothing to do with file I/O.
(Piped input and output streams are used in inter-thread communication.)
E fails because you cannot chain a data input stream onto a file reader.
Readers read chars, and input streams handle bytes.