Я пытаюсь прочитать файлы больших CSV и CSV и TSV (разделенные TAB) с примерно 1 000 000 строк или более. Теперь я пытался прочитать TSV, содержащий ~ 2 500 000 строк с OpenCSV, но он бросает java.lang.nullpointerException . Он работает с небольшими файлами TSV с ~ 250 000 строк. Поэтому мне было интересно, есть ли другие библиотеки, которые поддерживают чтение огромных файлов CSV и TSV. У вас есть идеи?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();
}
}
Это метод, в котором я конструирую inputstreamReader :
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();
}
Подробнее здесь: https://stackoverflow.com/questions/138 ... r-for-java