To clarify my question, I am writing to a text file located on my computer which has text content already in it. The code below writes to the text file without erasing any of its contents but now I want to specify what line it writes to. Currently it has an if statement to catch if the word 'Done' exists within in the line, it is recognized since it does write to the file. My problem is trying to get it to write to the line that says 'Done'. It writes to the very bottom, last line of code. How can I fix this?
The method readNumLines is the number of lines contained within the file. Reading is the text file name.
int i = 0;
BufferedReader reader = new BufferedReader(new FileReader(path+reading));
BufferedWriter writer = new BufferedWriter(new FileWriter(path+reading, true));
String line = null;
while ((line = reader.readLine()) != null && i < readNumLines(reading)-1) {
if(line.contains("Done")){
writer.write("\nCHECK!\n");
writer.close();
}
i++;
}