file path in hdfs

与世无争的帅哥 提交于 2020-01-01 04:35:08

问题


I want to read the file from the Hadoop File System.

In order to achieve the correct path of the file, I need host name and port address of the hdfs.

so finally my path of the file will look something like

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

Now I want to know to extract the HostName = "123.23.12.4344" & port: 9000?

Basically, I want to access the FileSystem on Amazon EMR but, when I use

 FileSystem fs = FileSystem.get(getConf());
I get
 
You possibly called FileSystem.get(conf) when you should have called FileSystem.get(uri, conf) to obtain a file system supporting your path
So I decided to use URI. (I have to use URI) but I am not sure how to access the URI.

回答1:


You can use either of the two ways to solve your error.

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


来源:https://stackoverflow.com/questions/13577767/file-path-in-hdfs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!