I use BufferedReader and PrintWriter to go through each line of the input file, make changes to some lines, and output the result. If the line does not undergo changes, it is simply printed as an output file. However, for some reason, the process ends prematurely. The code looks something like this:
BufferedReader in = new BufferedReader(new FileReader("in.txt"));
FileOutputStream out = new FileOutputStream("out.txt");
PrintWriter p = new PrintWriter(out);
String line = in.readLine();
while(line!=null)
{
if(line is special)
do edits and p.println(edited_line);
else
p.println(line);
line = in.readLine();
}
However, for some odd reason, this process ends prematurely (actually prints half the line) to the very end of my input file. Is there an obvious reason for this? The while loop explicitly ends with zero. And this is the end of my 250k + line txt file. Thanks!
source
share