hdfs中的java文件路径

bjp0bcyl  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(354)

我想从hadoop文件系统读取文件。
为了实现文件的正确路径,我需要文件的主机名和端口地址 hdfs .
所以最后我的文件路径看起来像

Path path = new Path("hdfs://123.23.12.4344:9000/user/filename.txt")

现在我想知道如何提取hostname=“123.23.12.4344”&port:9000?
基本上,我想访问amazonemr上的文件系统,但是

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。

fjaof16o

fjaof16o1#

您可以使用这两种方法中的任何一种来解决错误。

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());

相关问题