1. 程式人生 > >java 正則匹配 HDFS路徑後獲取目錄下檔案

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<LocatedFileStatus> 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();
        }
    }