Caching 在Hadoop上使用DistributedCache时未找到文件

Caching 在Hadoop上使用DistributedCache时未找到文件,caching,hadoop,distributed,file-not-found,Caching,Hadoop,Distributed,File Not Found,我在使用下面的代码时遇到了fileNotFound问题,这是对distributedCache的一个简单测试,我不知道是什么问题 文件路径正确,但在datanode上找不到文件: 包mapJoinTest2; /* *这适用于使用DistributedCache的映射联接 *使用类路径获取datanode中的缓存文件 * * 2012.1.13 * */ 导入java.io.BufferedReader; 导入java.io.FileNotFoundException; 导入java.io.

我在使用下面的代码时遇到了fileNotFound问题,这是对distributedCache的一个简单测试,我不知道是什么问题

文件路径正确,但在datanode上找不到文件:

包mapJoinTest2; /* *这适用于使用DistributedCache的映射联接 *使用类路径获取datanode中的缓存文件 * * 2012.1.13 * */ 导入java.io.BufferedReader; 导入java.io.FileNotFoundException; 导入java.io.FileReader; 导入java.io.IOException; 导入java.net.URI; 导入java.util.*; 导入org.apache.hadoop.filecache.DistributedCache; 导入org.apache.hadoop.fs.FileSystem; 导入org.apache.hadoop.fs.Path; 导入org.apache.hadoop.conf.*; 导入org.apache.hadoop.io.*; 导入org.apache.hadoop.mapred.*; 导入org.apache.hadoop.util.*; 公共类字数{ 公共静态类映射扩展MapReduceBase实现映射器{ 私有文本字=新文本; 私有文本映射键=新文本; 私有路径[]本地文件=新路径[1]; 专用文件系统fs; public void configureJobConf作业{ 试一试{ fs=FileSystem.getLocalnew配置; localFile=DistributedCache.getLocalCacheFilesjob; }捕获IOE1异常{ //TODO自动生成的捕捉块 e1.printStackTrace; } } public void mapLongWritable键、文本值、OutputCollector输出、Reporter报告器抛出IOException { forPath f:localFile{ System.out.printlnf.toString; } mapKey.setsuccess; output.collectmapKey,值; } } 公共静态无效主字符串[]args引发异常{ JobConf conf=new JobConfwordCount.class; conf.setJobNamewordcount; conf.setOutputKeyClassText.class; conf.setOutputValueClassText.class; conf.setMapperClassMap.class; conf.setNumReduceTasks0; conf.setInputFormatTextInputFormat.class; conf.setOutputFormatTextOutputFormat.class; FileInputFormat.setInputPathsconf,新路径参数[0]; FileOutputFormat.setOutputPathconf,新的Pathargs[1]; 字符串路径=hdfs://namenode:9000/hadoop/test1;//此文件已放在hdfs上。 路径filePath=新路径路径; 字符串uriWithLink=filePath.toUri.toString; DistributedCache.addCacheFilenew UriWithLink,conf; JobClient.runJobconf; } } 我在这里得到一个NullPointerException:

forPath f:localFile{ System.out.printlnf.toString; } 问题是因为f的值为null

我使用了下面的代码,但它不起作用

DistributedCache.createdSymlinkconf; DistributedCache.addCacheFilenew Pathhdfs://namenode:9000/hadoop/test1.toUri.toString ++test1,conf;
你用的是什么版本的Hadoop?我用0.22运行了这个程序,它可以正常工作。检查文件是否正确hdfs://namenode:9000/hadoop/test1 有没有。您需要创建完整的路径。对我来说,url是hdfs://localhost:9000/user/praveensripati/input/core-我使用hadoop 0.20.2,文件地址正确。即使我使用本地文件,例如/home/hadoop/temp/test1,它也会失败。