ネットからコピーした次の基本機能を使用してテキストファイルを読み取ります
public void read ()
{
File file = new File("/Users/MAK/Desktop/data.txt");
System.out.println("Start");
try
{
//
// Create a new Scanner object which will read the data from the
// file passed in. To check if there are more line to read from it
// we check by calling the scanner.hasNextLine() method. We then
// read line one by one till all line is read.
//
Scanner scanner = new Scanner(file);
int lineCount = 0;
if (scanner == null)
{
System.out.println("Null File");
}
else
{
System.out.println(scanner.toString());
}
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
System.out.println("Line " + lineCount +" contain : " + line);
lineCount++;
}
System.out.println("End of Try Bluck");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
System.out.println("Exception Bluck");
}
System.out.println("End");
}
}
中・小サイズのファイル(1~2万行のデータを含む)では問題なく動作しますが、50万行を含むファイルでは動作しませんでした。エラーは発生していません (少なくとも誰も見ていません)。それで何が起こっているのですか?このような大きなファイルを準備できるようにするには、ここで何をすればよいですか?
注: 4 GB の RAM で Windows Server 2008 を実行するテスト マシンでは、既に 2 GB のヒープを増やしました。しかし、これはあまり役に立ちませんでした!
ここで何をすべきか誰か教えてください。
更新 01
以下は出力です
始める
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skiped=false][group separator=\,] [小数点記号=.][正の接頭辞=][負の接頭辞=\Q-\E][正の接尾辞=][負の接尾辞=][NaN文字列=\Q�\E][無限大文字列=\Q∞\E ]
トライ・ブラック終了
終わり