Javaを使って、大きなテキストファイルを一行ずつ読むには?

5~6GB程度の大きなテキストファイルを、Javaを使って一行ずつ読む必要があります。

どうすれば早くできるでしょうか?

このブログを見て

  • Java Read File Line by Line - Java Tutorial]1をご覧ください。

バッファサイズを指定することもできますし デフォルトのサイズを使用することもできます。デフォルトは デフォルトは,ほとんどの目的のために十分な大きさです。 の目的には十分な大きさです。

// Open the file
FileInputStream fstream = new FileInputStream("textfile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));

String strLine;

//Read File Line By Line
while ((strLine = br.readLine()) != null)   {
  // Print the content on the console
  System.out.println (strLine);
}

//Close the input stream
fstream.close();
解説 (4)

スキャナークラスを使用することができます。

Scanner sc=new Scanner(file);
sc.nextLine();
解説 (5)

クラスBufferedReaderreadLine()`メソッドを使用する必要があります。 そのクラスから新しいオブジェクトを作成し、そのオブジェクトにこのメソッドを操作して、文字列に保存します。

BufferReader Javadoc.

解説 (1)