2014-12-23 81 views
-1

我有一些MapReduce作業,我想在Java代碼中進一步使用Reducer的輸出文件。如何從這樣的文件讀取數據,因爲它位於分佈式文件系統上?從減速器輸出文件讀取

感謝

+1

[讀取Java文件中的hdfs]的可能重複(http://stackoverflow.com/questions/13166123/reading-a-file-in-java-hdfs) – blackSmith

+0

可能重複[以編程方式讀取Hadoop的輸出Mapreduce程序](http://stackoverflow.com/questions/5634137/programmatically-reading-the-output-of-hadoop-mapreduce-program) – r2d2oid

回答

1

既然你想在一個簡單的Java代碼進一步使用減速機的輸出文件,您可以使用下面的代碼: -

` try{ 
Path pt=new Path("hdfs://npvm11.np.wc1.yellowpages.com:9000/user/john/abc.txt"); 
    FileSystem fs = FileSystem.get(new Configuration()); 
    BufferedReader br=new BufferedReader(new InputStreamReader(fs.open(pt))); 
    String line; 
    line=br.readLine(); 
    while (line != null){ 
    System.out.println(line); 
    line=br.readLine(); 
    } 
    } 
    catch(Exception e){ 
       }` 

與文件的地址替換地址你想在java代碼中使用它。