Considering the following class file, answer each of the questions given below.
ID: 3802485 • Letter: C
Question
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
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();
}
}
Explanation / Answer
11)Ans)false
Reason :in is as FileReader object
12)Ans)False
Reason:
out is a file writer object
13)Ans)false
Reason:
inputFile is a File Object Associated with inData.txt
14)Ans) false
Reason:
outputFile is a File Object Associated with outData.txt
15)Ans)true
both in.close and out.close are outside the block of the while loop
16)Ans)false
17)Ans)true
18)Ans)true
Reason:until the data left to read in the file ,the value of in.read is not equal to -1