I'm currently writing a small parser for files of the size ~500000 a very simple syntax, but reading the file is taking ages although the file is only 10 MB big.
Currently I have
public static String read(File file) {
BufferedReader reader = null;
String currentLine = "";
String text = "";
try {
reader = new BufferedReader(new FileReader(file));
while ((currentLine = reader.readLine()) != null) {
text += currentLine + "\n";
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (Exception e) {
}
}
return text;
}
As you might notice I'm inserting a line break on the end... This line break is needed for parsing...
What should I do in order to speed the process of reading up? I need the file in a single String...