本文整理汇总了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);
}
}
示例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);
}
示例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;
}
示例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;
}
});
}
示例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);
}
}
示例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;
}
});
}
}
示例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;
}
});
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
}
}
示例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;
}
示例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);
}
}
}
示例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 );
}
} );
}