java 文件系统 及HDFS系统读取目录下文件对比

首先 java实现
import java.io.File;

public class A {

 public static void  recursion(String root){
  File file = new File(root);
  File[] subFile = file.listFiles();
  for (int i = 0; i < subFile.length; i++) {
   if (subFile[i].isDirectory()) {
    System.out.println("目录: " + subFile[i].getName());
    recursion(subFile[i].getAbsolutePath());
   }else{
    System.out.println("文件: " + subFile[i].getName());
   }
  }
 }
 public static void main(String[] args) {
  recursion("D:/java");
 }
}


在搞下hadoop的

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.FileUtil; import org.apache.hadoop.fs.Path;

publi static void main(String[] args) throws Exception{
String uri = args[0];
Configuration conf = new Configuration();
Filesystem fs = FileSystem.get(URI.create(uri),conf);
Path[] paths = new Path[args.length];
for(int i=0; i<paths.length;i++)
{
paths[i] = new Path(args[i]);
}
FileStatus[] status = fs.listStatus(Paths);

Path[] listedPaths = FileUtil.stat2Paths(status);
for(Path p: listedPaths){
System.out.println(p);
}
}

你可能感兴趣的:(java,exception,String,File,Path,recursion)