分享

hdfs owner乱码

代码:
[mw_shl_code=java,true]package hdfs.operation;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class operateHdfs {
        public static void main(String args[]) throws IOException {
                byte[] contents = "hello world\n--created by eclipse\n".getBytes();
                System.out.println("begin");
                createFile("/input/first.txt", contents);
        }

        public static void createFile(String dst, byte[] contents) throws IOException {
                Configuration conf = new Configuration();
                System.out.println("-----------:" + conf);
                conf.set("fs.defaultFS", "hdfs://192.168.86.133:9000"); // master
                FileSystem fs = FileSystem.get(conf);
                Path dstPath = new Path(dst); //
                FSDataOutputStream outputStream = fs.create(dstPath);
                outputStream.write(contents);
                outputStream.close();
                fs.close();
                System.out.println("创建成功");
        }
}[/mw_shl_code]



创建后显示乱码:
[root@master ~]# hadoop fs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2017-06-07 22:30 /data
drwxr-xr-x   - æÂæ supergroup          0 2017-06-09 09:53 /input
drwxr-xr-x   - root supergroup          0 2017-06-08 00:55 /user


求解  owner乱码

已有(5)人评论

跳转到指定楼层
tntzbzc 发表于 2017-6-10 06:43:54
这是编码问题,Linux一般都为utf8,设置为gb2312即可。
Windows的默认编码为GBK,Linux的默认编码为UTF-8。在Windows下中文,在Linux下显示为乱码。为了解决此问题,修改Linux的默认编码为GBK。方法如下:

方法1:

vi   /etc/sysconfig/i18n

默认为:

LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"

修改为:

LANG="zh_CN.GBK"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh"
SYSFONT="latarcyrheb-sun16"

方法2:
vi /etc/profile

export LC_ALL="zh_CN.GBK"
export LANG="zh_CN.GBK"

回复

使用道具 举报

Wyy_Ck 发表于 2017-6-10 12:44:32
tntzbzc 发表于 2017-6-10 06:43
这是编码问题,Linux一般都为utf8,设置为gb2312即可。
Windows的默认编码为GBK,Linux的默认编码为UTF-8。 ...

谢谢, 我按照第二种方法设置后,还是乱码的  也执行了source /etc/profile

[root@master ~]# hadoop fs -ls /user
Found 2 items
drwxr-xr-x   - ???? supergroup          0 2017-06-10 00:42 /user/hadoop


回复

使用道具 举报

qcbb001 发表于 2017-6-10 14:26:30
Wyy_Ck 发表于 2017-6-10 12:44
谢谢, 我按照第二种方法设置后,还是乱码的  也执行了source /etc/profile

[root@master ~]# hadoop  ...

你用的是xshell,还是Linux shell。

回复

使用道具 举报

Wyy_Ck 发表于 2017-6-10 15:47:31
qcbb001 发表于 2017-6-10 14:26
你用的是xshell,还是Linux shell。

xshell  还有就是vmare linux shell 查看 都是乱码的
回复

使用道具 举报

einhep 发表于 2017-6-10 17:43:13
Wyy_Ck 发表于 2017-6-10 15:47
xshell  还有就是vmare linux shell 查看 都是乱码的

可以多尝试几种办法,这个就是编码的问题,如果楼主的window用户是英文的就不会出现这种情况了。
可以尝试修改下xshell的编码
xshell.jpg
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条