I want create text file but if the file already exists it should not create new file but should append the text to the content (at the end) of the existing file. How can I d
You can use the following code to append to a file which already exists -
try {
BufferedWriter out = new BufferedWriter(new FileWriter("filename", true));
out.write("data");
out.close();
} catch (IOException e) { }
If the second argument in FileWriter's constructor is true, then bytes will be written to the end of the file rather than the beginning.
Quoting Stephen's comment:
...passing
trueas the 2nd argument causes the file to be created if it doesn't exist and to be opened for appending if it does exist.