2014-01-22 58 views
0

我刚开始学习hadoop。下面提到的是我的java代码连接到hadoop hdfs。Hadoop dfs 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不是有效的文件名。

回答

0

那么,hdfs://localhost:54310是一个有效的URI但不是有效的文件名。

,则应指定URI的路径部分:

new Path("hdfs://localhost:54310/path/to/your/file.txt")