Suppose I have a file named abhishek.txt and that contains the following line
I am , and what is your name.
Now I want to write
I managed to do it using RandomAccessFile:
With this, you get a file containing exactly the expected 'I am Abhishek' content. This works even if you would had content after the first line, which you want to keep in the file(this was my initial problem: I had a large file and I had to insert some content after a certain String) rather than write at the end of the file, which is easier.