1.查看HDFS下所有的文件或目录
1 packageHdfs; 2 3 importjava.io.IOException; 4 importjava.net.URI; 5 importorg.apache.hadoop.conf.Configuration; 6 importorg.apache.hadoop.fs.FileStatus; 7 importorg.apache.hadoop.fs.FileSystem; 8 importorg.apache.hadoop.fs.Path; 9 10 public classListFiles { 11 public static voidmain(String[] args) { 12 String uri = "hdfs://neusoft-master:9000/user"; 13 Configuration conf = newConfiguration(); 14 try{ 15 FileSystem fs =FileSystem.get(URI.create(uri), conf); 16 Path Path = newPath(uri); 17 FileStatus[] status =fs.listStatus(Path); 18 for (int i = 0; i < status.length; i++) { 19 System.out.println(status[i].getPath().toString()); 20 } 21 fs.close(); 22 } catch(IOException e) { 23 e.printStackTrace(); 24 } 25 } 26 }
2.提交jar文件并查看结果
[root@neusoft-master hadoop]# hadoop jar /usr/local/software/JarListFiles.jar
3.验证上述结果~