Monday, 3 August 2009

Java Certification Question 0053

You need to read in the lines of a large text file containing tens of megabytes of data. Which of the following would be most suitable for reading in such a file

1) new FileInputStream("file.name")
2) new InputStreamReader(new FileInputStream("file.name"))
3) new BufferedReader(new InputStreamReader(new FileInputStream("file.name")));
4) new RandomAccessFile raf=new RandomAccessFile("myfile.txt","+rw");


Answer 3:

3) new BufferedReader(new InputStreamReader(new FileInputStream("file.name")));

The key to this question is that it asks about tens of megabytes of data, implying that performance is an issue. A Buffered Reader will optimise the performance of accessing a file. Although the objectives do not specifically mention it questions on I/O do come up on the exam.

No comments:

Post a Comment