Display hadoop file system recursively - Java Big Data

Java examples for Big Data:Hadoop

Description

Display hadoop file system recursively

Demo Code



import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class Task3 {

  public static void main(String[] args) throws IOException {
    Configuration conf = new Configuration();
    for(int i =0;i<args.length;i++)
    {/*from ww  w  . j  a  va 2s .c  o m*/
      String uri =args[i];
      Path path = new Path(uri);
      FileSystem fs = FileSystem.get(URI.create(uri), conf);
     displayrecursively(fs, path);
    }
  }
  
  public static void displayrecursively(FileSystem fs,Path path) throws FileNotFoundException, IOException
  {
    FileStatus[] filestatus = fs.listStatus(path);
    
    for(FileStatus fstat:filestatus)
    {
      if(fstat.isDirectory())
        System.out.println("Directory : "+fstat.getPath());
      
      displayrecursively(fs, fstat.getPath());
    }

  }

}

Related Tutorials