I noticed that use is java.util.Scannervery slow when reading large files (in my case, CSV files).
I want to change the way I read files now to improve performance. The following is what I have at the moment. Notice what I'm developing for Android:
InputStreamReader inputStreamReader;
try {
inputStreamReader = new InputStreamReader(context.getAssets().open("MyFile.csv"));
Scanner inputStream = new Scanner(inputStreamReader);
inputStream.nextLine();
while (inputStream.hasNext()) {
String data = inputStream.nextLine();
String[] line = data.split(",");
if (line.length > 1) {
String value = line[1];
}
}
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
Using Traceview , I was able to find that the main performance problems, in particular: java.util.Scanner.nextLine()and java.util.Scanner.hasNext().
I looked at other issues (like this one ) and I came across some CSV readers such as Apache Commons CSV , but they don't seem to have much information on how to use them, and I'm not sure how much faster they are.
FileReader BufferedReader , , , , .
30 000 , , (. ), 600 1 , , 2000 , , , Android .
, , , , FileReader BufferedReader. , , ? , , ( , ).