当前位置: 首页>>代码示例>>Java>>正文


Java Files.walkFileTree方法代码示例

本文整理汇总了Java中java.nio.file.Files.walkFileTree方法的典型用法代码示例。如果您正苦于以下问题:Java Files.walkFileTree方法的具体用法?Java Files.walkFileTree怎么用?Java Files.walkFileTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.walkFileTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveConfig

import java.nio.file.Files; //导入方法依赖的package包/类
static void resolveConfig(Environment env, final Settings.Builder settingsBuilder) {

        try {
            Files.walkFileTree(env.configFile(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    String fileName = file.getFileName().toString();
                    if (fileName.startsWith("logging.")) {
                        for (String allowedSuffix : ALLOWED_SUFFIXES) {
                            if (fileName.endsWith(allowedSuffix)) {
                                loadConfig(file, settingsBuilder);
                                break;
                            }
                        }
                    }
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException ioe) {
            throw new ElasticsearchException("Failed to load logging configuration", ioe);
        }
    }
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:LogConfigurator.java

示例2: compareFolders

import java.nio.file.Files; //导入方法依赖的package包/类
public void compareFolders(File expected, File result) throws IOException {
    final CollectFilesVisitor visitor = new CollectFilesVisitor();
    List<Path> resultFilesPaths = new ArrayList<>();
    List<Path> resultFoldersPaths = new ArrayList<>();

    visitor.setCollectedFilesList(resultFilesPaths);
    visitor.setCollectedFoldersList(resultFoldersPaths);

    Files.walkFileTree(result.toPath(), visitor);

    List<Path> expectedFilePaths = new ArrayList<>();
    List<Path> expectedFolderPaths = new ArrayList<>();
    visitor.setCollectedFilesList(expectedFilePaths);
    visitor.setCollectedFoldersList(expectedFolderPaths);

    Files.walkFileTree(expected.toPath(), visitor);

    logger.info("comparing {} paths", expectedFilePaths.size());
    assertContentCompares(expectedFilePaths, resultFilesPaths);
    assertNameCompares(expectedFolderPaths, resultFoldersPaths);

}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:23,代码来源:TestMavenPlugin.java

示例3: fromDir

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Builds a class path with all the files selected by the given predicate 
 * in the specified base directory and, recursively, in all of its 
 * sub-directories.
 * @param dir the directory in which to find the (jar) files.
 * @param select tests whether or not to include a regular file.
 * @return the class path.
 * @throws NullPointerException if the argument is {@code null}.
 * @throws IOException if an I/O error occurs while trawling the directory.
 */
public static ClassPath fromDir(Path dir, Predicate<Path> select) 
        throws IOException {
    requireNonNull(dir, "dir");
    requireNonNull(select, "select");
    
    ClassPath cp = new ClassPath();
    
    Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file,
                BasicFileAttributes attrs) throws IOException {
            if (attrs.isRegularFile() && select.test(file)) {
                cp.add(file);
            }
            return FileVisitResult.CONTINUE;
        }
    });
    
    return cp;
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:31,代码来源:ClassPathFactory.java

示例4: importSketchFiles

import java.nio.file.Files; //导入方法依赖的package包/类
private void importSketchFiles( Path sketchDirPath ) throws IOException {
    if ( !copyingFiles ) return;
    Files.walkFileTree(sketchDirPath, new CopyingFileVisitor(sketchDirPath, getSourceFilesDirectoryPath(), PROJECT_SOURCE_FILE_MATCHER) {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
            if ( file.toString().endsWith(".ino.cpp") ) {
                String filename = file.getFileName().toString();
                String newFilename = filename.replace(".ino.cpp", ".cpp");
                Path targetFilePath = target.resolve( source.relativize( Paths.get(file.getParent().toString(), newFilename) ) );
                copyFile( file, targetFilePath );
                try {
                    removeLineDirectives( targetFilePath);
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            } else { 
                copyFile( file, target.resolve( source.relativize(file) ) );
            }
            return CONTINUE;
        }            
    });
}
 
开发者ID:chipKIT32,项目名称:chipKIT-importer,代码行数:23,代码来源:ChipKitProjectImporter.java

示例5: close

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public void close() {
    memory.clear();
    try {
        Files.walkFileTree(tmpDir, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.deleteIfExists(file);
                return super.visitFile(file, attrs);
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                Files.deleteIfExists(dir);
                return super.postVisitDirectory(dir, exc);
            }
        });
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:kenzierocks,项目名称:HardVox,代码行数:23,代码来源:ChunkDataStore.java

示例6: removeDirectoryWithContent

import java.nio.file.Files; //导入方法依赖的package包/类
public static void removeDirectoryWithContent(Path directory) throws IOException {
	if (Files.isDirectory(directory)) {
		Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
			@Override
			public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
				Files.delete(file);
				return FileVisitResult.CONTINUE;
			}
			
			@Override
			public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
				Files.delete(dir);
				return FileVisitResult.CONTINUE;
			}
		});
	}
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:18,代码来源:PathUtils.java

示例7: removeRecursive

import java.nio.file.Files; //导入方法依赖的package包/类
public static void removeRecursive(final Path path) throws IOException {
  Files.walkFileTree(
      path,
      new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
            throws IOException {
          Files.deleteIfExists(file);
          return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
            throws IOException {
          Files.deleteIfExists(dir);
          return FileVisitResult.CONTINUE;
        }
      });
}
 
开发者ID:spotify,项目名称:bazel-tools,代码行数:20,代码来源:PathUtils.java

示例8: deleteFiles

import java.nio.file.Files; //导入方法依赖的package包/类
public static void deleteFiles (String path){    
	 try {
		 Path directory = Paths.get(path);
		 Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
		    @Override
		    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
		        Files.delete(file);
		        return FileVisitResult.CONTINUE;
		    }

		    @Override
		    public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
		        Files.delete(dir);
		        return FileVisitResult.CONTINUE;
		    }
		 });
	} catch (IOException e) {
		e.printStackTrace();
	}      
}
 
开发者ID:KayDeeTee,项目名称:Hollow-Knight-SaveManager,代码行数:21,代码来源:Listeners.java

示例9: deleteDirectory

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Deletes a directory recursively
 *
 * @param directory
 * @return true if deletion succeeds, false otherwise
 */
public static boolean deleteDirectory(Path directory) {
    if (directory != null) {
        try {
            Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    Files.delete(file);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                    Files.delete(dir);
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException ignored) {
            return false;
        }
    }
    return true;
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:29,代码来源:FileUploadHelper.java

示例10: showFiles

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * This method is primarily used to give visual confirmation that a test case
 * generated files when the compilation succeeds and so generates no other output,
 * such as error messages.
 */
List<Path> showFiles(Path dir) throws IOException {
    List<Path> files = new ArrayList<>();
    Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                throws IOException {
            if (Files.isRegularFile(file)) {
                out.println("Found " + file);
                files.add(file);
            }
            return FileVisitResult.CONTINUE;
        }
    });
    return files;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:SourcePathTest.java

示例11: testCleaner

import java.nio.file.Files; //导入方法依赖的package包/类
@Test
@Ignore("Assumes non-existing directory")
public void testCleaner() throws Exception {
  Set<File> fileSet = new HashSet<>();
  fileSet.add(new File("/Users/ecco/git/rs-aggregator/target/test-output/synchronizer/zandbak11.dans.knaw.nl/ehri2/mdx/__SOR__/ehri2/tmp/rs/collection2/folder1/doc1.txt"));
  fileSet.add(new File("/Users/ecco/git/rs-aggregator/target/test-output/synchronizer/zandbak11.dans.knaw.nl/ehri2/mdx/__SOR__/ehri2/tmp/rs/collection2/folder1/doc2.txt"));
  FileCleaner cleaner = new FileCleaner(fileSet);
  Path startingDir = Paths.get("target/test-output/synchronizer/zandbak11.dans.knaw.nl/ehri2/mdx/__SOR__");
  Files.walkFileTree(startingDir, cleaner);
}
 
开发者ID:EHRI,项目名称:rs-aggregator,代码行数:11,代码来源:FileCleanerTest.java

示例12: deleteGeneratedFiles

import java.nio.file.Files; //导入方法依赖的package包/类
private static void deleteGeneratedFiles() {
    Path p = Paths.get("generated");
    if (Files.exists(p)) {
        try {
            Files.walkFileTree(p, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file,
                                                 BasicFileAttributes attrs) throws IOException {

                    Files.delete(file);
                    return CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir,
                                                          IOException exc) throws IOException {

                    if (exc == null) {
                        Files.delete(dir);
                        return CONTINUE;
                    } else {
                        throw exc;
                    }
                }
            });
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:WsImportTest.java

示例13: receive

import java.nio.file.Files; //导入方法依赖的package包/类
private boolean receive(final Object o) throws IOException {
    tracer.info(started(hashCode).toString());
    if (o instanceof Closer) {
        tracer.info(finished(hashCode).toString());
        return true;
    }
    final Glob glob = (Glob) o;
    final PathTraversal pathTraversal = PathTraversal.create(glob.glob, out, workspacePath);
    Files.walkFileTree(Paths.get(glob.start), pathTraversal);
    tracer.info(finished(hashCode).toString());
    return false;
}
 
开发者ID:nfisher,项目名称:cljbuck,代码行数:13,代码来源:FindFilesTask.java

示例14: FromFilePath

import java.nio.file.Files; //导入方法依赖的package包/类
FromFilePath(Path path, ImportOptions importOptions) {
    this.importOptions = importOptions;
    if (path.toFile().exists()) {
        try {
            Files.walkFileTree(path, this);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:11,代码来源:ClassFileSource.java

示例15: setAllExecutable

import java.nio.file.Files; //导入方法依赖的package包/类
public static void setAllExecutable ( final Path directory, final boolean state ) throws IOException
{
    Files.walkFileTree ( directory, new SimpleFileVisitor<Path> () {
        @Override
        public FileVisitResult visitFile ( final Path file, final BasicFileAttributes attrs ) throws IOException
        {
            if ( Files.isRegularFile ( file, LinkOption.NOFOLLOW_LINKS ) )
            {
                setExecutable ( file, state );
            }
            return super.visitFile ( file, attrs );
        }
    } );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:Executables.java


注:本文中的java.nio.file.Files.walkFileTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。