0

I want to read only the first line of a file in Java and the number of files that i need to process is huge, somewhere around 50000.

I've gone through the API's BufferedReader, Scanner, FileUtils which all give utilities to read a file line by line. The size of my can very and can be huge.

I couldn't come to the conclusion if these API's read the entire files content into memory and then process it line by line.

Could anyone please clarify?

Thanks.

user320550
  • 1,093
  • 6
  • 20
  • 37

1 Answers1

0

As the name implies BufferedReader reads as much as the buffer size. From the Javadoc:

public class BufferedReader
extends Reader
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.

http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html