/**
 * 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"));
    }
}
Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐