栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java递归模糊查询文件

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java递归模糊查询文件

Java递归模糊查询文件 字符串模糊查询
    
    public boolean matchStringByIndexOf(String str,String part) {
        int count = 0;
        int index = 0;
        while( ( index = str.indexOf(part, index) ) != -1 )
        {
            index = index+part.length();
            count++;
        }
        if(count < 1){
            return false;
        }
        return true;
    }
递归遍历文件
    
    public List searchFileList(File path, String fileName){
        File[] files=path.listFiles();   //列出所有的子文件
        for(File file :files)
        {
            if(file.isFile()){//如果是文件,则先模糊查询,判断是否相关
                if(stringUtilService.matchStringByIndexOf(file.toString(),fileName)){
                    fileListData.add(file.toString());
                }
            }else if(file.isDirectory())//如果是文件夹,则输出文件夹的名字,并递归遍历该文件夹
            {
                searchFileList(file,fileName);//递归遍历
            }
        }
        return fileListData;
    }
测试
    public static void main(String[] args) {
        String A ="G:/HTML/testData/达芬奇";
        File file = new File(A);
        FileService fileService = new FileServiceImpl();
        System.out.println(fileService.searchFileList(file,"myse").toString());
    }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/461990.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号