java 正则匹配 HDFS路径后获取目录下文件

public static void main(String[] args) {
        URI uri = URI.create("hdfs://cdh-master:8020");
        FileSystem hdfs = null;
        Path path = new Path("/hiaAnalyticsService");
        try {
            hdfs = FileSystem.get(uri, conf, "hdfs");
            FileStatus[] files = hdfs.globStatus(path);
            for (FileStatus file : files) {
                //System.out.println(file.getPath());
                if (file.isDirectory()) {
                    RemoteIterator iterator = hdfs.listFiles(file.getPath(), false);
                    while (iterator.hasNext()) {
                        LocatedFileStatus fileStatus = iterator.next();
                        Path fullPath = fileStatus.getPath();
                        System.out.println(fullPath);
                    }
                } else {
                    System.out.println(file.getPath());
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

 

你可能感兴趣的:(java,hadoop)