如何使用FileWriter
實際寫入文件,然後在記事本中打開並查看我寫的內容?這是我試過到目前爲止:FileWriter寫入文件
package Experimental;
import java.io.*;
public class IO {
public static void main (String args[]) {
File f = new File("testFile.txt");
//Outputting into a file
try {
PrintWriter filePrint = new PrintWriter(
new BufferedWriter(new FileWriter(f,true))
);
filePrint.println("testing, testing, printing into a file (apparently)");
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
提高您的格式,請 – BackSlash
如果你用記事本打開該文件,會發生什麼?它打開它嗎? – RaviH
什麼問題? –