/** * Show how to write text to file. * @author Xuan Ngo */ import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; public class WriteToFile { public static void main(String[] args) { try { FileWriter oFileWriter = new FileWriter("filename.txt"); BufferedWriter oBufferedWriter = new BufferedWriter(oFileWriter); oBufferedWriter.write("Java"); oBufferedWriter.close(); } catch(IOException ex) { System.out.println(ex.getMessage()); } } }