本文整理了Java中com.google.common.io.Files.fileTraverser()
方法的一些代码示例,展示了Files.fileTraverser()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.fileTraverser()
方法的具体详情如下:
包路径:com.google.common.io.Files
类名称:Files
方法名:fileTraverser
[英]Returns a Traverser instance for the file and directory tree. The returned traverser starts from a File and will return all files and directories it encounters.
Warning: File provides no support for symbolic links, and as such there is no way to ensure that a symbolic link to a directory is not followed when traversing the tree. In this case, iterables created by this traverser could contain files that are outside of the given directory or even be infinite if there is a symbolic link loop.
If available, consider using MoreFiles#fileTraverser() instead. It behaves the same except that it doesn't follow symbolic links and returns Path instances.
If the File passed to one of the Traverser methods does not exist or is not a directory, no exception will be thrown and the returned Iterable will contain a single element: that file.
Example: Files.fileTraverser().breadthFirst("/") may return files with the following paths: ["/", "/etc", "/home", "/usr", "/etc/config.txt", "/etc/fonts", ...]
[中]返回文件和目录树的遍历器实例。返回的遍历程序从一个文件开始,并将返回它遇到的所有文件和目录。
警告:文件不支持符号链接,因此无法确保在遍历树时不遵循指向目录的符号链接。在这种情况下,由该遍历器创建的iterables可能包含给定目录之外的文件,如果存在符号链接循环,甚至可能是无限的。
如果可用,请考虑使用MuleFraseSyFielTraveServer()。除了不遵循符号链接并返回路径实例之外,它的行为相同。
如果传递给某个Traverser方法的文件不存在或不是目录,则不会引发异常,并且返回的Iterable将包含一个元素:该文件。
示例:文件。fileTraverser()。breadthFirst(“/”)可以返回具有以下路径的文件:[“/”、“/etc”、“/home”、“/usr”、“/etc/config.txt”、“/etc/font”、…]
代码示例来源:origin: google/guava
@Override
protected void scanDirectory(ClassLoader loader, File root) throws IOException {
URI base = root.toURI();
for (File entry : Files.fileTraverser().depthFirstPreOrder(root)) {
String resourceName = new File(base.relativize(entry.toURI()).getPath()).getPath();
resources.add(resourceName);
}
}
代码示例来源:origin: google/guava
public void testFileTraverser_nonExistingFile() throws Exception {
File file = new File(rootDir, "file-that-doesnt-exist");
assertThat(Files.fileTraverser().breadthFirst(file)).containsExactly(file);
}
代码示例来源:origin: google/guava
public void testFileTraverser_emptyDirectory() throws Exception {
assertThat(Files.fileTraverser().breadthFirst(rootDir)).containsExactly(rootDir);
}
代码示例来源:origin: google/guava
public void testFileTraverser_singleDirectory() throws Exception {
File file = newDir("some-dir");
assertThat(Files.fileTraverser().breadthFirst(rootDir)).containsExactly(rootDir, file);
}
代码示例来源:origin: google/guava
public void testFileTraverser_file() throws Exception {
File file = newFile("some-file");
assertThat(Files.fileTraverser().breadthFirst(file)).containsExactly(file);
}
代码示例来源:origin: google/guava
public void testFileTraverser_singleFile() throws Exception {
File file = newFile("some-file");
assertThat(Files.fileTraverser().breadthFirst(rootDir)).containsExactly(rootDir, file);
}
代码示例来源:origin: google/guava
public void testFileTraverser_multipleFilesAndDirectories() throws Exception {
File fileA = newFile("file-a");
File fileB = newFile("file-b");
File dir1 = newDir("dir-1");
File dir2 = newDir("dir-2");
assertThat(Files.fileTraverser().breadthFirst(rootDir))
.containsExactly(rootDir, fileA, fileB, dir1, dir2);
}
代码示例来源:origin: google/guava
public void testFileTraverser_multipleDirectoryLayers_traversalReturnsAll() throws Exception {
File fileA = newFile("file-a");
File dir1 = newDir("dir-1");
File fileB = newFile("dir-1/file-b");
File dir2 = newFile("dir-1/dir-2");
assertThat(Files.fileTraverser().breadthFirst(rootDir))
.containsExactly(rootDir, fileA, fileB, dir1, dir2);
}
代码示例来源:origin: google/guava
public void testFileTraverser_multipleDirectoryLayers_breadthFirstStartsWithTopLayer()
throws Exception {
File fileA = newFile("file-a");
File dir1 = newDir("dir-1");
newFile("dir-1/file-b");
newFile("dir-1/dir-2");
assertThat(Iterables.limit(Files.fileTraverser().breadthFirst(rootDir), 3))
.containsExactly(rootDir, fileA, dir1);
}
代码示例来源:origin: aimmac23/selenium-video-node
@Override
public void run() {
// close the native libraries in reverse order
disposeLibrary(xvfbInterface, "xvfb_interface");
disposeLibrary(encoder, "interface");
disposeLibrary(libMKV, "mkv");
disposeLibrary(yuvLib, "yuv");
disposeLibrary(libVPX, "vpx");
// Java File doesn't want to recursively delete things
Iterator<File> iterator = Files.fileTraverser().breadthFirst(extractedDirectory).iterator();
while(iterator.hasNext()) {
iterator.next().delete();
}
}
}, "JNA Shutdown Hook Thread");
代码示例来源:origin: com.github.cormoran-io.pepper/pepper
try (FileOutputStream fos = new FileOutputStream(zipFilePath); ZipOutputStream zos = new ZipOutputStream(fos)) {
Iterator<File> iterator = Files.fileTraverser().depthFirstPreOrder(folder).iterator();
代码示例来源:origin: Riverside-Software/sonar-openedge
ExecutorService service = Executors.newFixedThreadPool(4);
for (Path binDir : binariesDirs) {
Files.fileTraverser().depthFirstPreOrder(binDir.toFile()).forEach(f -> {
if (f.getName().endsWith(".r")) {
numRCode.incrementAndGet();
File dlc = new File(dlcInstallDir);
Files.fileTraverser().depthFirstPreOrder(new File(dlc, "gui")).forEach(f -> {
if (f.getName().endsWith(".pl")) {
service.submit(() -> parseLibrary(f));
代码示例来源:origin: angular/clutz
private List<File> getTestInputFilesRecursive(FilenameFilter filter, String... dir) {
ImmutableList.Builder<File> filesBuilder = ImmutableList.builder();
for (File f : Files.fileTraverser().depthFirstPreOrder(getTestDirPath(dir).toFile())) {
if (filter.accept(f.getParentFile(), f.getName())) {
filesBuilder.add(f);
}
}
return filesBuilder.build();
}
}
内容来源于网络,如有侵权,请联系作者删除!