深入浅出javase——NIO

/*

* nio包在JDK4出现,提供了IO流的操作效率。但是目前还不是大范围的使用。

* 有空的话了解下,有问题再问我。

*

* 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 void main(String[] args) throws IOException {

// public static long copy(Path source,OutputStream out)

// Files.copy(Paths.get("ByteArrayStreamDemo.java"), new

// FileOutputStream(

// "Copy.java"));

ArrayList array = new ArrayList();

array.add("hello");

array.add("world");

array.add("java");

Files.write(Paths.get("array.txt"), array, Charset.forName("GBK"));

}

}


分享到:


相關文章: