我有一些MapReduce作业,我想在Java代码中进一步使用Reducer的输出文件。由于该文件位于分布式文件系统上,因此如何读取?
谢谢
最佳答案
由于您想在一个简单的Java代码中进一步使用Reducer的输出文件,因此可以使用以下代码:
` 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代码中使用的文件的地址。
关于hadoop - 从 reducer 输出文件读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27617971/