84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
通过以下方式可以写文件
List<String> list = new ArrayList<String>(); list.add("第一行"); list.add("第二行"); list.add("第三行"); Path path = Paths.get("E:" + File.separator + "demo.txt"); Files.write(path, list, Charset.forName("UTF-8"));
但如果想每次执行都追加内容该怎么办呢?
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
First of all, it is better to write the code above like this (see):
Path path = Paths.get("E:", "demo.txt"); Files.write(path, list, StandardCharsets.UTF_8);
As for appending, just use the APPEND option of StandardOpenOption:
Files.write(path, list, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
First of all, it is better to write the code above like this (see):
As for appending, just use the APPEND option of StandardOpenOption: