java文件操作之递归获取视频文件

来源:互联网 发布:just do it 乔丹 编辑:程序博客网 时间:2024/06/06 16:26

代码:

static List<String> fileList = new ArrayList<String>();public static void getFileList(String path) {    if (path != null && !"".equals(path)) {        File file = new File(path);        if (file.exists()) {            File files[] = file.listFiles();            if (files.length > 0) {                for (File f : files) {                    if (f.isDirectory()) {                        // System.out.println("这是一个文件夹" +                        // f.getAbsolutePath());                        getFileList(f.getAbsolutePath());                    }                    String regx = "^.*?\\.(mp4|mp3|3gp|rmvb|wav|mkv|flv)$";                    if (Pattern.matches(regx, f.getName())) {                        // System.out.println("这是一个文件" +                        // f.getAbsolutePath());                        fileList.add(f.getAbsolutePath());                    }                }            } else {                System.out.println("该文件夹为空");            }        } else {            System.out.println("输入正确的地址 ");        }    } else {        System.out.println("输入正确的地址 ");    }}
0 0
原创粉丝点击