您的位置:首页 > 其它

用分布式缓存文件存储数据到本地 DistributedCache

2014-10-20 19:58 295 查看
main函数里:

Configuration conf = new Configuration();
Job job = new Job(conf, "kmeans job");
URI centersFile = new URI(
"hdfs://Master1Hadoop/user/image/centers/centersfile#cf"); // 设定要读入文件的信息
                                                                                   //centersfile为要分布式缓存的数据,#cf是为它起个别名
job.addCacheFile(centersFile); // 加入Cache,新API

Class xxx extends Mapper里:

public void setup(Context context) throws IOException, InterruptedException {
URI[] caches = context.getCacheFiles();
if (caches == null || caches.length <= 0) {
System.out.println("centers file does not exist");
System.exit(1);
}

BufferedReader br = new BufferedReader(new FileReader("./cf")); // 读取文件,这里的cf正是main里起得别名

String line;

while ((line = br.readLine()) != null) { // 每次读一行
System.out.println(line);
}

               br.close;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐