当前位置:   article > 正文

Files文件操作实现复制、移动_standardcopyoption.replace_existing

standardcopyoption.replace_existing

1、复制

StandardCopyOption.REPLACE_EXISTING:覆盖已有的目标路径
StandardCopyOption.COPY_ATTRIBUTES:复制所有的文件属性
Files.move(Paths.get("/app/test/filename.txt"),Paths.get("/app/test2/filename.txt"),StandardCopyOption.COPY_ATTRIBUTES);
  • 1
  • 2
  • 3

2、移动

Files.move(Paths.get("/app/test/filename.txt"),Paths.get("/app/test2/filename.txt"),StandardCopyOption.REPLACE_EXISTING);
  • 1

3、判断路径是否存在

Files.exists(Paths.get("/app/test/filename.txt"));
  • 1

4、创建文件

Files.createDirectories(Paths.get("/app/test/filename.txt"));
Files.createFile(Paths.get("/app/test/filename.txt"));
  • 1
  • 2

5、删除文件

Files.deleteIfExists(Paths.get("/app/test/filename.txt"));
  • 1

6、写入文件

Files.write(Paths.get("/app/test/filename.txt"),bytes,StandardOpenOption.APPEND)
  • 1

7、批量获取文件路径

Stream<Path> files = Files.list(Paths.get("/app/test/filename.txt"));
files.forEach(path -> doImport(path))
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/325242
推荐阅读
相关标签
  

闽ICP备14008679号