hdfs中的文件路径

Var*_*pta 10 java hadoop mapreduce amazon-ec2 amazon-emr

我想从Hadoop文件系统中读取文件.

为了实现文件的正确路径,我需要主机名和端口地址hdfs.

所以最后我的文件路径看起来像

Path path = new Path("hdfs://123.23.12.4344:9000/user/filename.txt")
Run Code Online (Sandbox Code Playgroud)

现在我想知道提取HostName ="123.23.12.4344"和端口:9000?

基本上,我想访问Amazon EMR上的FileSystem但是,当我使用时

 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.

Anu*_*jKu 15

您可以使用以下两种方法之一来解决错误.

1.

String infile = "file.txt";
Path ofile = new Path(infile);
FileSystem fs = ofile.getFileSystem(getConf());
Run Code Online (Sandbox Code Playgroud)

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());
Run Code Online (Sandbox Code Playgroud)

  • Hadoop有一个FileSystem工厂.它基于URI方案创建正确的文件系统,并且可能是URI的权限部分.您可以查看是否要在file://,s3://或hdfs://上打开文件,每个文件系统都需要不同的文件系统.这就是你需要包含URI的原因 (4认同)
  • fs.default.name 已弃用,这个问题的每个读者都应该使用 fs.defaultFS 代替。 (2认同)