美文网首页
File类中的listFiles方法的使用

File类中的listFiles方法的使用

作者: 果冻贱客 | 来源:发表于2016-12-07 00:15 被阅读0次

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;

}

}

}

相关文章

网友评论

      本文标题:File类中的listFiles方法的使用

      本文链接:https://www.haomeiwen.com/subject/ovcdmttx.html