In this section, you will learn how to write to a file using BufferedWriter.
What is BufferedWriter?
BufferedWriter buffer character to write characters, arrays and strings. It write text to a character-output stream.
Given below example will give you a clear idea :
import java.io.*;
public class FileWriteBufferedWriter {
public static void main(String[] args) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(
"NewDevFile.txt"));
out.write("Welcome to Devmanuals");
out.close();
System.out.println("File created successfully");
} catch (IOException e) {
}
}
}
If file created successfully, it will show you the following message :
| File created successfully |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Java BufferedWriter example
Post your Comment