s_puria
s_puria

Reputation: 407

Write a text in continue of a line in java

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

Answers (1)

Jordi Castilla
Jordi Castilla

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

Related Questions