In Java we can append a string in an existing file using FileWriter which has an option to open file in append mode.
Java FileWriter class is used to write character-oriented data to a file. It is character-oriented class which is used for file handling in Java. Unlike FileOutputStream class, we don’t need to convert string into byte array because it provides method to write string directly.
Note: The buffer size may be specified, or the default size may be used. A Writer sends its output immediately to the underlying character or byte stream.
Class constructor used:
FileWriter(File file, boolean append) – constructs a FileWriter object given a File object in append mode.
Class methods used:
void write(String s, int off, int len)
This method writes a portion of a String.
This method closes the stream after flushing it.
- Java.io.File Class in Java
- File Permissions in Java
- Delete a file using Java
- Java | Renaming a file
- Java Class File
- Myth about the file name and class name in Java
- Writing a CSV file in Java using OpenCSV
- Size of file on the Internet using Java
- How to run java class file which is in different directory?
- Check if a File is hidden in Java
- Copying file using FileStreams in Java
- Moving a file from one directory to another using Java
- How to play an Audio file using Java
- Reading a CSV file in Java using OpenCV
- File handling in Java using FileWriter and FileReader
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.