也许我的问题有点愚蠢,但我想在主机Windows环境(尤其是在eclipse中)访问hdfs文件。Hadoop和所有相关的东西都安装在VirtualBox上(用于带有Centos OS的Hortonworks Sandbox env。)。在虚拟机上,我可以毫无问题地使用hdfs,尝试访问hdfs://192.168.56.101:8020/user/root/vectors/dictionary.file-0
。尝试在eclipse上访问此文件,但出现了异常。
那么,有什么办法吗?如果可能的话,举个例子就很好了。
问题的主要原因是系统不知道我是谁。我需要hadoop的客户端,因此通过将客户端依赖项添加到pom中来解决了该问题:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.2.0</version>
</dependency>
这是工作示例:
public static void main(String[] args) throws Exception {
try {
Configuration conf = new Configuration();
conf.set("fs.default.name", "hdfs://192.168.56.101:8020");
FileSystem fs = FileSystem.get(conf);
Path pt = new Path("/user/root/vectors/dictionary.file-0");
BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(pt)));
try {
String line;
line = br.readLine();
while (line != null) {
System.out.println(line);
line = br.readLine();
}
} finally {
br.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句