我想从 Hadoop 文件系统读取文件。
为了获得正确的文件路径,我需要hdfs
的主机名和端口地址。
所以最后我的文件路径看起来像
Path path = new Path("hdfs://123.23.12.4344:9000/user/filename.txt")
现在我想知道如何提取 HostName = "123.23.12.4344"& port: 9000?
基本上,我想访问 Amazon EMR 上的文件系统,但是,当我使用
FileSystem fs = FileSystem.get(getConf());我得到
You possibly called FileSystem.get(conf) when you should have called FileSystem.get(uri, conf) to obtain a file system supporting your path所以我决定使用 URI。 (我必须使用 URI)但我不确定如何访问 URI。
最佳答案
您可以使用这两种方法中的任何一种来解决您的错误。
1.
String infile = "file.txt";
Path ofile = new Path(infile);
FileSystem fs = ofile.getFileSystem(getConf());
2.
Configuration conf = getConf();
System.out.println("fs.default.name : - " + conf.get("fs.default.name"));
// It prints uri as : hdfs://10.214.15.165:9000 or something
String uri = conf.get("fs.default.name");
FileSystem fs = FileSystem.get(uri,getConf());
关于java - hdfs中的文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13577767/