首页 > 编程 > Java > 正文

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

2019-11-06 09:24:11
字体:
来源:转载
供稿:网友

代码:

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("输入正确的地址 "); }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表