java – hdfs中的文件路径
发布时间:2020-12-14 05:31:39 所属栏目:Java 来源:网络整理
导读:我想从Hadoop文件系统中读取文件. 为了实现文件的正确路径,我需要hdfs的主机名和端口地址. 所以最后我的路径的文件将看起来像 Path path = new Path("hdfs://123.23.12.4344:9000/user/filename.txt") 现在我想知道提取HostName =“123.23.12.4344”港口:90
我想从Hadoop文件系统中读取文件.
为了实现文件的正确路径,我需要hdfs的主机名和端口地址. 所以最后我的路径的文件将看起来像 Path path = new Path("hdfs://123.23.12.4344:9000/user/filename.txt") 现在我想知道提取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. 解决方法
您可以使用两种方法来解决您的错误.
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()); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读