首页 > 其他 > 详细

File-FilenameFilter接口

时间:2019-09-25 10:31:21      阅读:111      评论:0      收藏:0      [点我收藏+]
import java.io.*;
public class Practice_3 {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        File dir = new File("c:\\新建文件夹\\note");
        
        String[] arr = dir.list(new FilenameFilter()
                {
                    public boolean accept(File dir ,String name)
                    {
                        return true;          //如果返回值为false,则默认地址中无文件, 所以list底层调用了该方法。
                    }
                }
              );
        sop(arr.length);
        for( String s : arr)
        {
            sop(s);
        }
    }
    public static void sop(Object obj)
    {
        System.out.println(obj);
    }

}



过滤器:
import java.io.*;
public class Practice_3 {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        File dir = new File("c:\\新建文件夹\\note");
        
        String[] arr = dir.list(new FilenameFilter()
                {
                    public boolean accept(File dir ,String name)
                    {
                        sop("dir::"+dir+"....name::"+name);
                        
                        return name.endsWith(".java");
                    }
                }
                                );
        
        sop(arr.length);
        for( String s : arr)
        {
            sop(s);
        }
    }
    public static void sop(Object obj)
    {
        System.out.println(obj);
        
    }
}

 


 

File-FilenameFilter接口

原文:https://www.cnblogs.com/zxl1010/p/11582431.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!