hadoop中文乱码问题

1.hadoop默认编码上utf-8
2.如果输入文件如果是保存成utf-8格式,则wordcount.java程序中不需要转码,输出文件也是uft-8文件格式;
如果输出文件格式为其他格式,则在wordcount.java程序中需要对其转码,如果不转换编码,在程序打钱出输入文件内容时中文显示为乱码,转到GBK后,输出文件中的内容自动生成到输出文件时格式为utf-8.
3.在Xshell中查看输出文件时,使用命令/home/hadoop/hadoop/bin/hadoop fs -cat /wanghongen/demo/fileout/wordcount_out1/part-r-00000前,要将Xshell客户端的encoding编码设置为utf-8才能正常看到输出文件的内容。



public static Text transformText(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);
    }

你可能感兴趣的:(hadoop)