How to write into a file in java

Write into a file in java:-
In this article we will have a brief look on how to write into a file in java using BufferedWriter. BufferedWriter works almost similar to FileWriter but it uses internal buffer to write the text into a file. BufferedWriter is used in java to write to a file when number of write operations is more.
import java.io.*;
public class Main
{
public static void main(String[] args)
{
try
{
BufferedWriter out = new
BufferedWriter(new FileWriter(“outfilename”));
out.write(“aString”);
out.close();
System.out.println(“File created successfully”);
}

catch (IOException e)
{
}
}
}

Output:-
File created successfully

Leave a Reply