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写文件十分的简洁!!!

    原文作者:Freeland丶
    原文地址: https://blog.csdn.net/u013078669/article/details/52766809
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞