HDFS的Java客户端操作代码(查看HDFS下所有的文件或目录)

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.FileStatus;
 7 import org.apache.hadoop.fs.FileSystem;
 8 import org.apache.hadoop.fs.Path;
 9 
10 public class ListFiles {
11     public static void main(String[] args) {
12         String uri = "hdfs://neusoft-master:9000/user";
13         Configuration conf = new Configuration();
14         try {
15             FileSystem fs = FileSystem.get(URI.create(uri), conf);
16             Path Path = new Path(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 }
查看HDFS下所有的文件

 

2.提交jar文件并查看结果

[root@neusoft-master hadoop]# hadoop jar /usr/local/software/JarListFiles.jar 

    

3.验证上述结果~

    

 

转载于:https://www.cnblogs.com/jackchen-Net/p/6266927.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值