gpt4 book ai didi

java - 为什么 Hadoop FileSystem.get 方法需要知道完整的 URI 而不仅仅是方案

转载 作者:可可西里 更新时间:2023-11-01 14:25:28 27 4
gpt4 key购买 nike

是否可以使用从任何有效的 hdfs url 创建的 Hadoop 文件系统实例再次用于读取和写入不同的 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));

这可行。但这会导致任何其他问题吗?

最佳答案

您当然可以使用您的方案和地址创建一个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"));

关于java - 为什么 Hadoop FileSystem.get 方法需要知道完整的 URI 而不仅仅是方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13152619/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com