1

I have a file called "contatti.txt" with some contact info, I need to write a string into a specific line of the txt file.

For example, I need to change the content of line 32 with "something..."

This is the code that let me write this file in append mode

File filee=new File("contatti.txt");

BufferedWriter bw=new BufferedWriter(new FileWriter(filee,true));
???
bw.close();
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
Percival
  • 29
  • 1
  • 6
  • 2
    Create new temporary file, copy N-1 original lines to it, create modified version of N-th line and write it to temporary file, copy rest of the lines to temporary file. Replace original file with temporary one. – Pshemo Mar 07 '20 at 19:42
  • 2
    Is this SO question not the same as your question? [Java Replace Line In Text File](https://stackoverflow.com/questions/20039980/java-replace-line-in-text-file) – Abra Mar 07 '20 at 19:47
  • Yes, thanks. I'll try it – Percival Mar 07 '20 at 19:51

0 Answers0