A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 游泳的猫 中级黑马   /  2014-11-25 23:39  /  702 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

代码如下:
package studyreflect;

import java.io.UnsupportedEncodingException;

public class CharCode {

        /**
         * @param args
         * @throws UnsupportedEncodingException
         */
        public static void main(String[] args) throws UnsupportedEncodingException {
                System.getProperties().put("file.encoding", "iso8859-1");
                System.getProperties().list(System.out);
                String str="中国";
                byte[] buf=str.getBytes();
                for(int i=0;i<buf.length;i++){
                        System.out.println(Integer.toHexString(buf[i]));
                }
                for(int i=0;i<buf.length;i++){
                        System.out.write(buf[i]);
                }
                System.out.println();

        }
}
问题1.这是《java就业培训》书中的一段代码,书中的最后结果"中国"不能打印出来,可是我的能,不知道为什么?求解答,这道题的答案关系到第二题。。。
问题2.System.out.println("中国")这句代码的具体过程,书中是这样说的:先把“中国”转换其GB2312码的字节数组,然后调用write方法将这字节数组写入到输出流中。这样对吗?
以上两道题急求大神解答,现在这里谢谢了。。。。。



0 个回复

您需要登录后才可以回帖 登录 | 加入黑马