I am using BufferedReader (br) and BufferedWriter (bw) to read a very large file, do calculations, and write the results on the output file. The output file will have the same number of lines as in the input file.
What I am currently doing is getting data from the input file line by line (while br.readLine() != null), do the calculations of the line I just read, then write the result of this single calculation onto the output file (br.write) then write a new line (bw.newLine()). This loop repeats until it reaches the end of the file.
This works not bad.. but it takes me 1 second to process 3500 input lines. I have been told that it is two much as the code will be tested with MUCH LARGER files. What is the best practice I should use (both read and write)? Can I keep my results as chunks in the buffer until specific limit an then write to the actual file?
EDIT: I think the reading/performing calculation part is good, but how about writing by keeping parts in the buffer then writing to the output file? Is there a good way to avoid writing every iteration?