这将起作用,并进行一些修改-我假设您粘贴的代码被截断了:
Path pt=new Path("hdfs://pathTofile");FileSystem fs = FileSystem.get(context.getConfiguration());BufferedReader br=new BufferedReader(new InputStreamReader(fs.open(pt)));try { String line; line=br.readLine(); while (line != null){ System.out.println(line); // be sure to read the next line otherwise you'll get an infinite loop line = br.readLine(); }} finally { // you should close out the BufferedReader br.close();}您可以有多个映射器读取同一个文件,但是使用分布式缓存存在更多的局限性(不仅减少了承载文件块的数据节点的负载,而且效率也会更高)如果您的工作任务数量大于任务节点数量)



