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 NIO {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        Files.copy(Paths.get("f4.jpg"), new FileOutputStream("copy.jpg"));

//      ArrayList<String> array=new ArrayList<String>();
//      array.add("hello");
//      array.add("java");
//      Files.write(Paths.get("array.txt"),array,Charset.forName("GBK"));
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章