我刚刚开始学习Hadoop。 下面提到的是我连接到Hadoop HDFS的Java代码。
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
BufferedReader reader = new BufferedReader(new InputStreamReader(fs.open(new Path("hdfs://localhost:54310"))));
String line = null;
line = reader.readLine();
while(line!=null){
System.out.println(line);
line = reader.readLine();
}
reader.close();
fs.close();
我收到错误消息,指出 hdfs://localhost:54310 不是有效的文件名。
好吧,hdfs://localhost:54310
是一个有效的URI,但不是有效的文件名。
应指定 URI 的路径部分:
new Path("hdfs://localhost:54310/path/to/your/file.txt")