ファイル(非常に大きい)を読み取るためにopenCSVを使用しているJavaのアプリケーションがあります。次に、4番目の列(最終的には、違いが生じる場合は1つまたは2つの列が追加されます)をHashSetに入れ、それを新しいファイルに出力します。これはすべて正常に動作しているように見えますが、ファイルの一部 (272,948 行中 131,544 行) しか読み取っていないことがわかりました。これは openCSV または Java の一般的な制限ですか、それともこれを回避する方法はありますか?
参照用の私のコード:
public static void main(String[] args) throws IOException {
String itemsFile = new String();
String outFile = new String();
itemsFile = "items.txt";
outFile = "so.txt";
CSVReader reader = null;
try {
reader = new CSVReader(new FileReader(itemsFile), '\t');
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
String[] nextLine;
HashSet<String> brands = new HashSet<>();
while ((nextLine = reader.readNext()) != null) {
brands.add(nextLine[4]);
}
String[] brandArray = new String[brands.size()];
Iterator<String> it = ((HashSet<String>) brands).iterator();
int listNum = 0;
while (it.hasNext()) {
Object brand = (Object) it.next();
brandArray[listNum] = (String) brand;
listNum++;
}
CSVWriter writer = new CSVWriter(new FileWriter(outFile), '\n');
writer.writeNext(brandArray);
writer.close();
}
私のコードが乱雑で申し訳ありませんが、これは私の最初の実際の「完成した」Java アプリケーションです。どんな支援も大歓迎です。
これらの行をtxtファイルから削除して、文字などでハングアップしていないことを確認しましたが、とにかくその行で停止しているようです