是否可以使用从任何有效的hdfs url创建的Hadoop FileSystem实例再次用于读取和写入不同的hdfs url.我尝试了以下
String url1 = "hdfs://localhost:54310/file1.txt";
String url2 = "hdfs://localhost:54310/file2.txt";
String url3 = "hdfs://localhost:54310/file3.txt";
//Creating filesystem using url1
FileSystem fileSystem = FileSystem.get(URI.create(url1), conf);
//Using same filesystem with url2 and url3
InputStream in = fileSystem.open(new Path(url2));
OutputStream out = fileSystem.create(new Path(url3));
Run Code Online (Sandbox Code Playgroud)
这有效.但这会引起任何其他问题.
你当然可以FileSystem
用你的计划和地址创建一个单一的,然后通过FileSystem
.
Configuration conf = new Configuration();
conf.set("fs.default.name","hdfs://localhost:54310");
FileSystem fs = FileSystem.get(conf);
InputStream is = fs.open(new Path("/file1.txt"));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11569 次 |
最近记录: |