Java写入文件
Java如何写入文件?
解决方法
此示例演示如何使用BufferedWriter类的write方法写入文件。
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) { } } }
结果
上面的代码示例将产生以下结果。
File created successfully.