// files/Find.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.// {ExcludeFromGradle}import java.nio.file.*;public class Find {public static voidmain(String[] args) throws Exception {Path test = Paths.get("test");Directories.refreshTestDir();Directories.populateTestDir();// Creating a *directory*, not a file:Files.createDirectory(test.resolve("dir.tmp"));PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**/*.{tmp,txt}");Files.walk(test).filter(matcher::matches).forEach(System.out::println);System.out.println("***************");PathMatcher matcher2 = FileSystems.getDefault().getPathMatcher("glob:*.tmp");Files.walk(test).map(Path::getFileName).filter(matcher2::matches).forEach(System.out::println);System.out.println("***************");Files.walk(test) // Only look for files.filter(Files::isRegularFile).map(Path::getFileName).filter(matcher2::matches).forEach(System.out::println);}}/* Output:test\bag\foo\bar\baz5208762845883213974円.tmptest\bag\foo\bar\baz\File.txttest\bar\baz\bag\foo7918367201207778677円.tmptest\bar\baz\bag\foo\File.txttest\baz\bag\foo\bar8016595521026696632円.tmptest\baz\bag\foo\bar\File.txttest\dir.tmptest\foo\bar\baz\bag5832319279813617280円.tmptest\foo\bar\baz\bag\File.txt***************5208762845883213974.tmp7918367201207778677.tmp8016595521026696632.tmpdir.tmp5832319279813617280.tmp***************5208762845883213974.tmp7918367201207778677.tmp8016595521026696632.tmp5832319279813617280.tmp*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。