HDFS的Java客户端操作代码(查看HDFS下的文件是否存在)详解

查看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 }
发布了276 篇原创文章 · 获赞 109 · 访问量 24万+

猜你喜欢

转载自blog.csdn.net/lvtula/article/details/100115374