nirjari patel wrote:Does it mean that I can not modify the existing files without creating new files ?
You cannot open the same file for reading and writing at the same time and edit it in the way that you're trying to do with the code above.
nirjari patel wrote:Is there a way to store all the lines in an arraylist and write entire arraylist to the file ?
with br.readLine(), I can read one line at a time and with br.read(), I can read one character at a time. How can I read entire file at once rather than reading line by line ?
Ofcourse, you can read the entire contents of the file into for example an ArrayList in memory, then change the content of the ArrayList, and then write it back. There's no easy, built-in way to read in the file with a single statement. But reading or writing a file line by line is not so hard. Do something like this:
First read the file: open it for reading, use a BufferedReader to read all the lines in a loop (calling readLine() on the BufferedReader until it returns null).Then edit the text in the ArrayList.Then write the file: open it for writing, use a PrintWriter to write all the lines in a loop.
Try writing some code to do that and let us know how it works out!