FilenameFilter的用法

import java.util.*; import java.io.*; public class JavaFilter implements FilenameFilter{ public boolean containUDDI(String file){ return file.contains(".java"); } public boolean accept(File dir,String name){ return containUDDI(name); } public static void main(String [] args){ File files=new File("c:/test"); String [] list; list=files.list(new JavaFilter()); }

这样,string数组list里面就保存了C盘test文件夹下面所有包含.java字符的文件

你可能感兴趣的:(javase)