Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1063451
  • 博文数量: 284
  • 博客积分: 8223
  • 博客等级: 中将
  • 技术积分: 3188
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-01 13:26
文章分类

全部博文(284)

文章存档

2012年(18)

2011年(33)

2010年(83)

2009年(147)

2008年(3)

分类: Java

2010-07-27 13:35:08

import java.io.*;
class FileAccept implements FilenameFilter
{
    String str = null;
    FileAccept(String s)
    {
        str=s;
    }
    public boolean accept(File dir, String name)
    {
        return name.endsWith(str);
    }
}
public class test {

    /**
     * @param args
     */

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        String dirname = "./";
        File f1 = new File(dirname);
        if(f1.isDirectory()){
            System.out.println("Directory of "+dirname);
            FilenameFilter only = new FileAccept("bin");
            String s[]=f1.list(only);
            for(int i =0;i<s.length;i++){
                File f= new File(dirname +"/"+s[i]);
                if(f.isDirectory()){
                    System.out.println(s[i]+" is a directory");
                }else{
                    System.out.println(s[i]+" is a file");
                }
            }
        }
    }

}


阅读(1256) | 评论(0) | 转发(0) |
0

上一篇:java文件系统

下一篇:java-输入输出流

给主人留下些什么吧!~~