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.
- Delete a file using Java
- Java Class File
- File Permissions in Java
- Java | Renaming a file
- Java.io.File Class in Java
- How to run java class file which is in different directory?
- Myth about the file name and class name in Java
- Check if a File is hidden in Java
- Moving a file from one directory to another using Java
- Copying file using FileStreams in Java
- Writing a CSV file in Java using OpenCSV
- Size of file on the Internet using Java
- How to play an Audio file using Java
- Reading a CSV file in Java using OpenCV
- File list() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.