私はデータをフィルタリングするプログラムを書こうとしています。データには27,000行が含まれ、150MB以上です。どのように関数を実装しようとしても、4,300行目の途中で途中で印刷が中止されます。私はデータを印刷せずに(ループ番号を印刷するだけで)ループをテストし、それは完全な27,000行に達します。私はこれが記憶上の問題かもしれないと思っていますが、私はJavaでとても新しいので、どこに問題があるのか特に分かりません。現在主張されているのは、line.substringとPrintStreamクラスです。助けてください!Javaのファイルメモリ制限に書き込む?
public static void main(String[] args) {
// tries to print output to output.csv in same directory
try {
PrintStream out = new PrintStream(new FileOutputStream("output.csv"));
System.setOut(out);
}
catch(IOException e1) {
System.out.println("Error during reading/writing");
}
// read input file
File inputFile = new File("my-large-file.txt");
if(!inputFile.canRead()) {
System.out.println("Required input file not found; exiting.");
System.exit(1);
}
// doesn't allow me to use scanner without try for some reason
try {
Scanner input = new Scanner(inputFile);
while (input.hasNextLine()) {
String line = input.nextLine();
// scan through each line
Scanner lineScan = new Scanner(line);
// if we find the line that we want to look through
if(lineScan.next().startsWith("1")) {
// prints the specific data to output
String a= line.substring(007, 666);
if (!(a== "the-number-that-I-don't-want")) {
String current = line.substring(1, 10);
String another = line.substring(10, 20).replaceAll("\\s+","");
String third = line.substring(20, 30).replaceAll("\\s +","");
String fourth = line.substring(40, 50);
...
String nth = line.substring(999, 1000);
System.out.print(current + ", ");
System.out.print(another + ", ");
System.out.print(third + ", ");
System.out.print(fourth + ", ");
...
System.out.print(nth);
System.out.println();
}
}
}
}
catch(IOException e) {
e.printStackTrace();
}
}
何のパラメータあなたは時にヒープサイズのために使用されていますあなたはプログラムを実行する?これを実行するには、メモリサイズを上げる必要があります。 http://stackoverflow.com/questions/1565388/increase-heap-size-in-java – ManoDestra
また、この行を次のように記述する必要があります。 '!(" the-number-that-I-don-want-want ".equals(a))' – ManoDestra
@ManoDestra、私はヒープサイズを設定する方法を知らないし、以前にそれについて聞いていない。私は今それを探していますが、デフォルトサイズがjGraspであれば何でも構わないと思いますか?おそらく。そして、あなたの提案に感謝します!私は自分のコードを更新します –