Java_Core_IO

2019-10-22

 

 ===============================

2019-10-24  06:18:19

Files.walkFileTree(path, filterFilesVisitor)

class FileterFilesVisitor extends SimpleFileVisitor<Path>

 

 

 

 

final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(matcherStr);

pathMatcher.matches(string) : boolean

==========================

2019-10-24

为了获取 .xml 后缀的文件, 不能使用 String endsWith() 方法,  它会忽略点  .xml  , 而直接获取到  xml,  逻辑上有缺陷

例如文件的名字后三位就是 xml  ,但文件类型确非 xml 格式。

===================================================

 2019-10-25

visitor walkFileTree 删除一个目录树, 非空

 1 private void deleteUnexpectedFolder(Path uploadPath)throws IOException{
 2         if(!uploadPath.toFile().exists()){
 3             return;
 4         }
 5 
 6         // delete the same folder exist
 7         Files.walkFileTree(uploadPath, new SimpleFileVisitor<Path>() {
 8 
 9             public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
10                 Files.delete(file);
11                 return FileVisitResult.CONTINUE;
12             }
13 
14             public FileVisitResult postVisitDirectory(Path dir, IOException ex) throws IOException {
15                 if (ex != null) throw ex;
16                 Files.delete(dir);
17                 return FileVisitResult.CONTINUE;
18             }
19         });
20     }

==

处理 ZIP 文件系统

 

posted @ 2019-10-22 13:33  君子之行  阅读(82)  评论(0编辑  收藏  举报