- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to Append Text to an Existing File
The Java.io.BufferedWriter class writes text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings. To add contents to a file −
- Instantiate the BufferedWriter class.
- By passing the FileWriter object as an argument to its constructor.
- Write data to the file using the write() method.
Example
import java.io.File; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.IOException; public class AppendToFileExample { public static void main( String[] args ) { try { String data = " Tutorials Point is a best website in the world"; File f1 = new File("C:\Users\files\abc.txt"); if(!f1.exists()) { f1.createNewFile(); } FileWriter fileWritter = new FileWriter(f1.getName(),true); BufferedWriter bw = new BufferedWriter(fileWritter); bw.write(data); bw.close(); System.out.println("Done"); } catch(IOException e){ e.printStackTrace(); } } }
Output
Done
- Related Articles
- Golang program to append a string in an existing file
- How to add/append content to an existing file using Java?
- Append to an existing file stored in SD Card connected to Arduino
- C++ program to append content of one text file to another
- How to append text to a text file in C++?
- C# Program to make a copy of an existing file
- How to append data to a file in Java?
- How to append a second list to an existing list in C#?
- Java program to delete duplicate lines in text file
- Java program to delete certain text from a file
- How to add a JSON string to an existing JSON file in Java?
- Append list of dictionaries to an existing Pandas DataFrame in Python
- Check whether the given file is an existing file in Java
- How can I append text to JTextArea in Java?
- How to create a duplicate file of an existing file using Python?

Advertisements