java8 write file 写文件

用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 !!"); }

用 Files.write()写入文件

String content = "Hello World !!"; Files.write(Paths.get("c:/output.txt"), content.getBytes());



从以上两种方式可以看出用java8写文件十分的简洁!!!

你可能感兴趣的:(java)