package filetest; import java.io.*; public class writefile { public static void main(String[] args) { // TODO 自动生成的方法存根 PrintWriter out = null; File f = new File("c:\\temp3.txt"); try{ out = new PrintWriter(new FileWriter(f)); } catch(IOException e){ e.printStackTrace(); } //由FileWriter实例化,则向文件中输出 out.print("Hello World!"+"\r\n"); out.close(); } }