1.用BufferedWriter写入文件
//Get the file reference Path path = Paths.get("c:/output.txt"); //Use try-with-resource to get auto-closeable writer instance try (BufferedWriter writer = Files.newBufferedWriter(path)) { writer.write("Hello World !!"); }
2.用 Files.write()写入文件
String content = "Hello World !!"; Files.write(Paths.get("c:/output.txt"), content.getBytes());