设为首页 加入收藏

TOP

Hadoop涉及GBK编码的文件
2014-11-24 07:15:02 来源: 作者: 【 】 浏览:1
Tags:Hadoop 涉及 GBK 编码 文件

输入文件为GBK,则只需在mapper或reducer程序中读取Text时,使用transformTextToUTF8(text, "GBK");进行一下转码,以确保都是以UTF-8的编码方式在运行。


public static Text transformTextToUTF8(Text text, String encoding) {
String value = null;
try {
value = new String(text.getBytes(), 0, text.getLength(), encoding);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return new Text(value);
}


输出文件为GBK,则重写TextOutputFormat类,public class GBKFileOutputFormat extends FileOutputFormat,把TextOutputFormat的源码拷过来,然后把里面写死的utf-8编码改成GBK编码。最后,在run程序中,设置job.setOutputFormatClass(GBKFileOutputFormat.class);


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇使用Hadoop MapReduce 进行排序 下一篇shell自动化配置Hadoop配置文件示..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)