hdfs获取文件列表,利用正则表达式选择文件并作下一步处理

来源:互联网 发布:vm12安装mac 编辑:程序博客网 时间:2024/04/27 13:28
Configuration conf = new Configuration();FileSystem hdfs = FileSystem.get(URI.create(args[1]),conf);FileStatus[] listStatus = hdfs.listStatus(new Path(args[1]));Path[] listPath = FileUtil.stat2Paths(listStatus);for(Path p : listPath){String fileNamePath = p.toString();//获得带路径的文件名字符串String fileName = p.getName();//获取文件名String regex = "keyword+//-[0-9]+//-r+//-00000";//keyword-00-r-00000Pattern pattern = Pattern.compile(regex);Matcher matcher = pattern.matcher(fileName);if(matcher.matches()){      //找到满足的文件,做下一步处理}
0 0
原创粉丝点击