File类中的listFiles方法的使用

listFiles()

Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

File[]listFiles(FileFilterfilter)

Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

File[]listFiles(FilenameFilterfilter)

Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

翻译:

listFiles()

返回表示此抽象路径名所表示的目录中的文件的抽象路径名数组。

File [] listFiles(FileFilter filter)

返回一个抽象路径名数组,表示此抽象路径名所指向的目录中满足指定过滤器的文件和目录。

File [] listFiles(FilenameFilter filter)

返回一个抽象路径名数组,表示此抽象路径名所指向的目录中满足指定过滤器的文件和目录。

示例:

public class myFileFilter implements FileFilter{

@Override

public boolean accept(File pathname) {   //此处重写accept方法

String filename = pathname.getName().toLowerCase(); /*toLowerCase()将字符串中的字母全部改成小写*/

if(filename.contains(".txt")){

returnfalse;

}else{

returntrue;

}

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容