Read from reducer output file

若如初见. 提交于 2019-12-25 18:26:41

问题


I have some MapReduce job and I would like to use the output file of Reducer further in Java code. How can I read from such a file, since it's on distributed file system?

Thanks


回答1:


Since you want to use output file of Reducer further in a simple java code, for that you can use the following code:-

` 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){
                }`

Replace the address with the address of file which you want to use in java code.



来源:https://stackoverflow.com/questions/27617971/read-from-reducer-output-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!