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.