MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

files/Find.java:9–37  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class Find {
9 public static void
10 main(String[] args) throws Exception {
11 Path test = Paths.get("test");
12 Directories.refreshTestDir();
13 Directories.populateTestDir();
14 // Creating a *directory*, not a file:
15 Files.createDirectory(test.resolve("dir.tmp"));
16
17 PathMatcher matcher = FileSystems.getDefault()
18 .getPathMatcher("glob:**/*.{tmp,txt}");
19 Files.walk(test)
20 .filter(matcher::matches)
21 .forEach(System.out::println);
22 System.out.println("***************");
23
24 PathMatcher matcher2 = FileSystems.getDefault()
25 .getPathMatcher("glob:*.tmp");
26 Files.walk(test)
27 .map(Path::getFileName)
28 .filter(matcher2::matches)
29 .forEach(System.out::println);
30 System.out.println("***************");
31
32 Files.walk(test) // Only look for files
33 .filter(Files::isRegularFile)
34 .map(Path::getFileName)
35 .filter(matcher2::matches)
36 .forEach(System.out::println);
37 }
38}
39/* Output:
40test\bag\foo\bar\baz\5208762845883213974.tmp

Callers

nothing calls this directly

Calls 4

refreshTestDirMethod · 0.95
populateTestDirMethod · 0.95
walkMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected