java open and write to text file 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");
}
}