2 feijikaikai001 feijikaikai001 于 2016.09.12 06:09 提问

求问对于转换流的底层实现
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in,"utf-8"));
    char []c=new char[4];
    int x=br.read(c);

    BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out,"gbk"));
    bw.write(c,0,x);
    bw.flush();

    这样输出的是问好

        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    char []c=new char[4];
    int x=br.read(c);

    BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out,"utf-8"));
    bw.write(c,0,x);
    bw.flush();

    这样可以输出你好

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in,"gbk"));
    char []c=new char[4];
    int x=br.read(c);

    BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out,"utf-8"));
    bw.write(c,0,x);
    bw.flush();

    这样输出的浣犲ソ。
    想知道当我在输入中文的时候,读取时是否转换成了字节。

1个回答

kaka20099527
kaka20099527   2016.09.12 09:27

乱码的关键是字节数据是用什么编码转的

Csdn user default icon
上传中...
上传图片
插入图片