标签:dir oid lte 获取 类型 files package nod list
package File; import java.io.File; import java.io.FilenameFilter; public class FileNameSelector implements FilenameFilter { String extension = "."; public FileNameSelector(String fileExtensionNoDot) { extension += fileExtensionNoDot; } @Override public boolean accept(File dir, String name) { return name.endsWith(extension); } public static void main(String[] args) { File directory = new File("E:\\"); // 列出所有文件 File[] files = directory.listFiles(); System.out.println("\n目录" + directory.getName() + "下的所有文件"); for (File file : files) { System.out.print(" " + file.getName()); } // 列出所有.txt文件 File[] txtFiles = directory.listFiles(new FileNameSelector("txt")); System.out.println("\n目录" + directory.getName() + "下的.txt文件"); for (File file : txtFiles) { System.out.print(" " + file.getName()); } // 列出所有.java文件 File[] javaFiles = directory.listFiles(new FileNameSelector("java")); System.out.println("\n目录" + directory.getName() + "下的.java文件"); for (File file : javaFiles) { System.out.print(" " + file.getName()); } } }
标签:dir oid lte 获取 类型 files package nod list
原文地址:https://www.cnblogs.com/xiaokaivip/p/9240339.html