设为首页 加入收藏

TOP

Hadoop涉及GBK编码的文件
2014-11-24 07:15:02 来源: 作者: 【 】 浏览:0
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配置文件示..

评论

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

·MySQL 安装及连接-腾 (2025-12-25 06:20:28)
·MySQL的下载、安装、 (2025-12-25 06:20:26)
·MySQL 中文网:探索 (2025-12-25 06:20:23)
·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)