Aja*_*jay 3 java hadoop mapreduce hdfs
我试图使用JAVA列出HDFS中的所有目录和文件.
Configuration configuration = new Configuration();
FileSystem fs = FileSystem.get(new URI("hdfs://ip address"), configuration);
FileStatus[] fileStatus = fs.listStatus(new Path("hdfs://ip address/user/uname/"));
Path[] paths = FileUtil.stat2Paths(fileStatus);
for(FileStatus status : fileStatus){
System.out.println(status.getPath().toString());
}
Run Code Online (Sandbox Code Playgroud)
我的代码能够生成fs对象,但卡在第3行,在这里它尝试读取文件的文件夹和文件.我正在使用AWS.
请帮我解决这个问题.
Kis*_*ore 10
这对我有用..
public static void main(String[] args) throws IOException, URISyntaxException {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(new URI("hdfs://localhost:9000/"), conf);
FileStatus[] fileStatus = fs.listStatus(new Path("hdfs://localhost:9000/"));
for(FileStatus status : fileStatus){
System.out.println(status.getPath().toString());
}
}
Run Code Online (Sandbox Code Playgroud)
产量
hdfs://localhost:9000/All.txt
hdfs://localhost:9000/department.txt
hdfs://localhost:9000/emp.tsv
hdfs://localhost:9000/employee.txt
hdfs://localhost:9000/hbase
Run Code Online (Sandbox Code Playgroud)
它认为你给的是不正确的uri.尝试按照代码做.
如果未设置conf,则必须添加资源文件
conf.addResource(new Path("/home/kishore/BigData/hadoop/etc/hadoop/core-site.xml"));
conf.addResource(new Path("/home/kishore/BigData/hadoop/etc/hadoop/hdfs-site.xml"));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12872 次 |
| 最近记录: |