java 21

1:JDK4  新IO要了解的类

Buffer(缓冲),Channer(通道)

2:JDK7  要了解的新IO类

  Path:与平台无关的路径。

  Paths:包含了返回Path的静态方法。

  public static Path get(URI uri):根据给定的URI来确定文件路径。 Files:操作文件的工具类。提供了大量的方法,

简单了解如下方法

  public static long copy(Path source, OutputStream out) :复制文件

  public static Path write(Path path, Iterable<? extends CharSequence> lines, Charset cs, OpenOption... options): 把集合的数据写到文件。

1 //复制文件
2 Files.copy(Paths.get("Demo.java"), newFileOutputStream("Copy.Java"));
3 
4 //把集合中的数据写到文件
5 List<String> list = new ArrayList<String>();
6 list.add("hello");
7 list.add("world");
8 list.add("java");
9 Files.write(Paths.get("list.txt"), list, Charset.forName("gbk"));
何事都只需坚持.. 难? 维熟尔。 LZL的自学历程...只需坚持
原文地址:https://www.cnblogs.com/LZL-student/p/5932001.html