9 If a sequential file is opened for input then this allows
9.
If a sequential file is opened for input, then this allows data to be placed into the file by the Java application.
(a) True (b) False
(10) Which of the terms in the following line of code are named variables that could be replaced as long as all other references were also updated?
FileReader in = new FileReader(inFile);
(a) inFile (b) in (c) new (d) File (e) FileReader
Considering the following class file, answer each of the questions given below.
import java.io.*; import java.io.FileReader;
import java.io.FileWriter;
public class ReadWrite {
public static void main(String[] args) throws IOException {
File inputFile = new File(\"inData.txt\");
File outputFile = new File(\"outData.txt\");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile, true);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
}
(11) in is a FileWriter object. (a) True (b) False
(12) out is a FileReader object. (a) True (b) False
(13) inputFile is a File object associated with outData.txt . (a) True (b) False
(14) outputFile is a File object linked with inData.txt . (a) True (b) False
(15) out.close() is outside the block of the while loop. (a) True (b) False
(16) in.close() is inside the block of the while loop. (a) True (b) False
(17) The while loop is used to both read from and write to the file. (a) True (b) False
(18) (c = in.read()) != -1 is true when data can still be read. (a) True (b) False
(19) The loop condition is false when the end of file marker is reached. (a) True (b) False
(20) FileWriter(outputFile, true) allows for appending. (a) True (b) False
| import java.io.*; import java.io.FileReader; import java.io.FileWriter; public class ReadWrite { public static void main(String[] args) throws IOException { 
 File inputFile = new File(\"inData.txt\"); File outputFile = new File(\"outData.txt\"); FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile, true); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); } } | 
Solution
(9)----------(b) False
10-------------(a) inFile
11-------------(a) True
12-------------(a) True
13-------------(b) False
14---------------(b) False
15---------------(a) True
16---------------(b) False
17----------------(a) True
18----------------(b) False
19-----------------(b) False
20------------------(a) True


