How to list all files in a directory and its subdirectories in hadoop hdfs

后端 未结 9 1066
故里飘歌
故里飘歌 2020-12-01 05:50

I have a folder in hdfs which has two subfolders each one has about 30 subfolders which,finally,each one contains xml files. I want to list all xml files giving only the mai

9条回答
  •  清歌不尽
    2020-12-01 06:18

    Have you tried this:

    import java.io.*;
    import java.util.*;
    import java.net.*;
    import org.apache.hadoop.fs.*;
    import org.apache.hadoop.conf.*;
    import org.apache.hadoop.io.*;
    import org.apache.hadoop.mapred.*;
    import org.apache.hadoop.util.*;
    
    public class cat{
        public static void main (String [] args) throws Exception{
            try{
                FileSystem fs = FileSystem.get(new Configuration());
                FileStatus[] status = fs.listStatus(new Path("hdfs://test.com:9000/user/test/in"));  // you need to pass in your hdfs path
    
                for (int i=0;i

提交回复
热议问题