六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 231|回复: 0

FilenameFilter接口 示例

[复制链接]

升级  57%

113

主题

113

主题

113

主题

举人

Rank: 3Rank: 3

积分
371
 楼主| 发表于 2013-2-5 02:40:00 | 显示全部楼层 |阅读模式
import java.io.*;
public class OnlyExt implements FilenameFilter{
 String strExt;
 public OnlyExt(String strExt){
  this.strExt = "." + strExt;
 }
 public boolean accept(File fleDir,String strName){
  return strName.endsWith(strExt);
 }
}
//Directory of .TXT files.
import java.io.*;
class DirListOnly{
 public static void main(String[] args)
 {
  String strDirName = "c:/winnt";
  File f1 = new File(strDirName);
  FilenameFilter only = new OnlyExt("txt");
  String s[] = f1.list(only);
  for(int i=0;i<s.length;i++){
   System.out.println(s[i]); 
  }
 }
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表