Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

hdfs java read all files in directory

/**
 * @param filePath
 * @param fs
 * @return list of absolute file path present in given path
 * @throws FileNotFoundException
 * @throws IOException
 */
public static List<String> getAllFilePath(Path filePath, FileSystem fs) throws FileNotFoundException, IOException {
    List<String> fileList = new ArrayList<String>();
    FileStatus[] fileStatus = fs.listStatus(filePath);
    for (FileStatus fileStat : fileStatus) {
        if (fileStat.isDirectory()) {
            fileList.addAll(getAllFilePath(fileStat.getPath(), fs));
        } else {
            fileList.add(fileStat.getPath().toString());
        }
    }
    return fileList;
}

// Example
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String filePath = "hdfs://localhost:9000/a/dir/here";
Path path = new Path(filePath);
FileSystem fs = path.getFileSystem(conf);

filePath = Tools.getAllFilePath(new Path(filePath), fs).get(0);
System.out.println(Tools.getAllFilePath(new Path(filePath), fs));
Comment

PREVIOUS NEXT
Code Example
Java :: change short video to byte array android 
Java :: how to call super onbackpressed in fragment 
Java :: java android build secret keys 
Java :: finding length of arrays in java 
Java :: how to set java path in windows 10 
Java :: how to use enumUtils in java 
Java :: how to convert character into operator 
Java :: what are parameters in java 
Java :: how to pass schema name in jdbc url 
Java :: find the unique element in a list java 
Java :: Sending String from one activity to another 
Java :: make a textarea not editable javafx 
Java :: format print java 
Java :: android java how to stop activity from opening twice programatically 
Java :: How to initialize a 3d array in Java? 
Java :: arraylist to primitive array 
Java :: java set file folder permissions 
Java :: char value java 
Java :: android java turn off night mode 
Java :: resultset next method 
Java :: exception in java 
Java :: what is object in java 
Java :: refresh sharedpreferences going back java 
Java :: localbroadcastmanager android example 
Java :: java clear bufffer to take next string inpuit 
Java :: java break string at comma 
Java :: kotlin spinner default value 
Java :: mergesort java 
Java :: lcm of two number in java 
Java :: data structure java 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =