how to write to an file in java code example
Example: Java program to write to text file
// Java program to write to text file
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class WriteIntoTextFile
{
public static void main(String[] args)
{
try
{
FileWriter fw = new FileWriter("B:\\demo.txt");
fw.write("Hello World");
fw.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
System.out.println("Successful");
}
}