首页
学习
活动
专区
圈层
工具
发布

总结java中文件拷贝剪切的5种方式-JAVA IO基础总结第五篇

StandardCopyOption.COPY_ATTRIBUTES //copy文件的属性,最近修改时间,最近访问时间等 }; Files.copy(fromFile, toFile, options); 二、文件重命名 NIO中可以使用Files.move...newFile.txt"); Path target = Paths.get("D:\data\test\renameFile.txt"); //REPLACE_EXISTING文件存在就替换它 Files.move...throws IOException { Path source = Paths.get("D:\data\test\newFile.txt"); //这种写法就更加简单,兼容性更好 Files.move...:\data\test\renameFile.txt")); System.out.println(succeeded); //失败了false,没有异常 } 三、文件剪切 文件剪切实际上仍然是Files.move...anotherDir = Paths.get("D:\data\test\anotherDir"); //目标文件夹 Files.createDirectories(anotherDir); Files.move

1.5K42
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到
    领券