I use BufferedReader
and FileReader
on very big files (~100g).
Here is the code I'm using:
BufferedReader reader = new BufferedReader(new FileReader("file path"));
BufferedWriter writer = new BufferedWriter(new FileWriter("output file"));
String line;
while ((line = reader.readLine()) != null) {
// check if i need this line, and if i need it, i print it
writer.write(line);
writer.newLine();
}
writer.close();
reader.close();
When I run this on my files in the beginning it uses a low amount of memory but slowly the used memory grows (can easily use over than 50GB of RAM).
Why it's like that? And, can I fix it somehow?