큰 CSV
및 TSV
(Tab sepperated) 파일 약 1000000
행 이상을 읽으려고합니다. 이제 을 ~2500000
개의 줄이 포함 된 opencsv
으로 읽으려고했으나 java.lang.NullPointerException
이 표시됩니다. ~250000
개의 줄이있는 작은 파일 TSV
과 함께 작동합니다. 그래서 큰 CSV
및 TSV
파일을 읽을 수있는 다른 Libraries
이 있는지 궁금합니다. 아이디어가 있습니까?Java 용 Good and effective CSV/TSV Reader
모두 (내가 그렇게 Try-Catch
분명히 잘못된, 그것을 단축) :
InputStreamReader in = null;
CSVReader reader = null;
try {
in = this.replaceBackSlashes();
reader = new CSVReader(in, this.seperator, '\"', this.offset);
ret = reader.readAll();
} finally {
try {
reader.close();
}
}
편집 :
private InputStreamReader replaceBackSlashes() throws Exception {
FileInputStream fis = null;
Scanner in = null;
try {
fis = new FileInputStream(this.csvFile);
in = new Scanner(fis, this.encoding);
ByteArrayOutputStream out = new ByteArrayOutputStream();
while (in.hasNext()) {
String nextLine = in.nextLine().replace("\\", "/");
// nextLine = nextLine.replaceAll(" ", "");
nextLine = nextLine.replaceAll("'", "");
out.write(nextLine.getBytes());
out.write("\n".getBytes());
}
return new InputStreamReader(new ByteArrayInputStream(out.toByteArray()));
} catch (Exception e) {
in.close();
fis.close();
this.logger.error("Problem at replaceBackSlashes", e);
}
throw new Exception();
}
BufferedReader 덕분에 직접 읽지 않는 이유는 무엇입니까? –
실제로 저는 잘 만들어진 코드와 공통적 인 코드를 원했고 휠을 재발 명하고 싶지 않았습니다. 실제로 모든 사람들이 생각하는 libs를 사용하고 있습니다. 그러나 아무런 효과가 없다면 그렇게 할 것입니다. – Robin
그 많은 행을 나는 일괄 적으로 파일을 처리 할 것이다 : 파일에서 n 줄을 읽고 csv로 처리하고 다음 일괄 처리를 읽는다. – opi