Answer the question
In order to leave comments, you need to log in
BufferedReader or Scanner?
Good evening. Googled enough already and nowhere did I find the 1st specific opinion or given specific numbers.
What is better to use for reading and splitting text (for example, CSV) files of a huge size
Banal code example:
String filePath = "C:/test.csv";
InputStreamReader isr = new InputStreamReader(new FileInputStream(filePath), "UTF-8");
BufferedReader br = new BufferedReader(isr);
String line;
while((line = br.readLine()) != null) {
String[] splited = line.split("\t");
for (int i = 0; i < splited.length; i++) {
System.out.println(splited[i]);
}
}
Answer the question
In order to leave comments, you need to log in
Now, in terms of speed, they are almost the same.
However, Scanner has useDelimiter(Pattern)
and methods findInLine(Pattern)
that allow you to instantly search for delimiters, so it's .csv
better to use it for files.
In general, why reinvent the wheel if there are wonderful Apache Commons CSV or opencsv
libraries ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question