Java Reference
In-Depth Information
6. public MyReader(File file) throws IOException {
7. FileReader fr = new FileReader(file);
8. in = new BufferedReader(fr);
9. }
10.
11. public void go() throws IOException {
12. String s = null;
13. while((s = in.readLine()) != null) {
14. System.out.print(s);
15. }
16. }
17.
18. public static void main(String [] args) {
19. try {
20. File file = new File(“data.txt”);
21. new MyReader(file).go();
22. }catch(IOException e) {
23. e.printStackTrace();
24. }
25. }
26. }
what is the output of the MyReader program if the fi le “data.txt” is in the same direc-
tory as MyReader.class and contains the following contents:
H
E
L
L
O
A. The characters HELLO with each character on a separate line.
B. The characters HELLO on the same line.
C. The character 'H'.
D. An IOException is thrown on line 13.
E. The code does not compile.
11. Suppose you need to write data that consists of ints, doubles, booleans, and strings
to a file that maintains the format of the original data. The data needs to be buffered to
improve performance. Which three java.io classes can be chained together to best achieve
this result?
A. FileWriter
B. FileOutputStream
Search WWH ::




Custom Search