/*
* 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.add("hello");
array.add("world");
array.add("java");
Files.write(Paths.get("array.txt"), array, Charset.forName("GBK"));
}
}
閱讀更多 java課堂 的文章