1.查看HDFS目录下得文件是否存在
1 package Hdfs; 2 3 import java.io.IOException; 4 import java.net.URI; 5 import org.apache.hadoop.conf.Configuration; 6 import org.apache.hadoop.fs.FileSystem; 7 import org.apache.hadoop.fs.Path; 8 9 public class CheckFileExist { 10 public static void main(String[] args) { 11 String uri = "hdfs://neusoft-master:9000/user/root/test1"; 12 Configuration conf = new Configuration(); 13 try { 14 FileSystem fs = FileSystem.get(URI.create(uri), conf); 15 Path delPath = new Path(uri); 16 boolean isExists = fs.exists(delPath); 17 System.out.println(isExists); 18 } catch (IOException e) { 19 e.printStackTrace(); 20 } 21 } 22 23 }
HDFS查看文件是否存在
2.打包jar运行并显示结果
[[email protected] hadoop]# hadoop jar /usr/local/software/JarCheckFileExist.jar
3.验证结果
[[email protected] hadoop]# hadoop dfs -ls /user/root/
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8935.html