Reputation: 407
In Java I want to write a String to end of a specific line in file. The simple way:
BufferedWriter bw = new BufferedWriter(new FileWriter(file,true));
bw.write(String);
does not work because it always writes at the end of file. Is there a simple way?
Upvotes: 1
Views: 437
Reputation: 26961
You have to get the line number where you want to add the string.... Then iterate over the the file with readLine()
.
while (br.readLine() != null) {
if (actualLine == yourLine) // write the String
actualLine ++;
}
Upvotes: 1