Java将这个特定的模式定义为内置的glob过滤器。
import java.io.IOException; import java.nio.file.DirectoryStream;/**N o w J a v a . c o m - 时 代 Java**/ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void main(String[] args) { Path path = Paths.get("C:/folder1/folder2/folder4"); //glob pattern applied System.out.println("\nGlob pattern applied:"); try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, "*.{png,jpg,bmp}")) { for (Path file : ds) { /**来自 n o w j a v a . c o m - 时 代 Java**/