1.查看HDFS目录下得文件是否存在
1 packageHdfs; 2 3 importjava.io.IOException; 4 importjava.net.URI; 5 importorg.apache.hadoop.conf.Configuration; 6 importorg.apache.hadoop.fs.FileSystem; 7 importorg.apache.hadoop.fs.Path; 8 9 public classCheckFileExist { 10 public static voidmain(String[] args) { 11 String uri = "hdfs://neusoft-master:9000/user/root/test1"; 12 Configuration conf = newConfiguration(); 13 try{ 14 FileSystem fs =FileSystem.get(URI.create(uri), conf); 15 Path delPath = newPath(uri); 16 boolean isExists =fs.exists(delPath); 17 System.out.println(isExists); 18 } catch(IOException e) { 19 e.printStackTrace(); 20 } 21 } 22 23 }
2.打包jar运行并显示结果
[root@neusoft-master hadoop]# hadoop jar /usr/local/software/JarCheckFileExist.jar
3.验证结果
[root@neusoft-master hadoop]# hadoop dfs -ls /user/root/