If you want to overwrite the same file with your new lines you should do first all the reading, and then all the writing.
ArrayList<String> lines = new ArrayList<String>();
//start reader, go over each line
while (line != null) {
String newLine = //make changes to line
lines.add(newLine);
}
//close reader
//start writer
//write each line to file