我如何使用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());
}
}
}
Run Code Online (Sandbox Code Playgroud)