I need to read a large text file of around 5-6 GB line by line using Java.
How can I do this quickly?
FileReader won't let you specify the encoding, use InputStreamReader
instead if you need to specify it:
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "Cp1252"));
String line;
while ((line = br.readLine()) != null) {
// process the line.
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
If you imported this file from Windows, it might have ANSI encoding (Cp1252), so you have to specify the encoding.