- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Writing data to a file using BufferedWriter class in Java
The BufferedWriter class of Java is used to write a stream of characters to the specified destination (character-output stream). It initially stores all the characters in a buffer and pushes the contents of the buffer to the destination, making the writing of characters, arrays and Strings efficient.
You can specify the required size of the buffer at the time of instantiating this class.
Example
In the following Java program, we are trying to print a line on the console (Standard Output Stream). Here we are invoking the write() method by passing the required String.
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; public class BufferedWriterExample { public static void main(String args[]) throws IOException { //Instantiating the OutputStreamWriter class OutputStreamWriter out = new OutputStreamWriter(System.out); //Instantiating the BufferedWriter BufferedWriter writer = new BufferedWriter(out); //Writing data to the console writer.write("Hello welcome to Tutorialspoint"); writer.flush(); } }
Output
Hello welcome to Tutorialspoint
- Related Articles
- Writing UTF8 data to a file using Java
- Writing a CSV file in Java using OpenCSV
- Writing data from database to .csv file
- Writing Text to File Using Linux Cat Command
- How to read data in from a file to String using java?
- Reading UTF8 data from a file using Java
- Python - Writing to an excel file using openpyxl module
- Reading and Writing CSV File using Python
- Writing a binary file in C++
- What is the purpose of the flush() method of the BufferedWriter class in java?
- Writing a Pandas DataFrame to CSV file
- What is the use of in flush() and close() methods of BufferedWriter class in Java?
- How to use file class in Java?
- How to append data to a file in Java?
- File Upload using Selenium WebDriver and Java Robot Class.

Advertisements