Java JDK7的之后的NIo的新特性

Path:路径

Paths:有一个静态方法返回一个路径

public static Path get(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)

案例:

 public class NIODemo {
    //第一种方式
    // public static long copy(Path source,OutputStream out)
    // Files.copy(Paths.get("ByteArrayStreamDemo.java"), new
    // FileOutputStream(
    // "Copy.java"));

    //第二种方式
    ArrayList<String> array = new ArrayList<String>();
    array.add("hello");
    array.add("world");
    array.add("java");
    Files.write(Paths.get("array.txt"), array, Charset.forName("GBK"));
    }
}

猜你喜欢

转载自blog.csdn.net/qinwendou/article/details/78682530