标题:字符编码
只看楼主
tgnian
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2007-4-13
 问题点数:0 回复次数:0 
字符编码
输入中国怎么照样得到正确编码?
import *;
public class CharDecoder
{
    public static void main(String [] args) throws Exception
    {
        System.getProperties().put("file.encoding","iso8859-1");
        System.out.println("please enter a Chinese String");
        byte [] buf=new byte[1024];
        int ch=0;  
        int pos=0;
        String strInfo=null;
        while(true)
        {            
        ch =System.in.read();
        System.out.println(Integer.toHexString(ch));
        switch(ch)
        {
            case '\r':
                break;
            case '\n':
                strInfo= new String(buf,0,pos);
                for(int i=0;i<strInfo.length();i++)
                {
                    System.out.println(Integer.toHexString
                        (/*(int)*/strInfo.charAt(i)));
                }
                System.out.println(strInfo);//如输入中国怎么还能输出中国
                return;
            default:
                buf[pos++]=(byte)ch;
        }
        }            
    }
}

运行例子:
D:\>java CharDecoder
please enter a Chinese String
中国
d6
d0
b9
fa
d
a
4e2d
56fd
中国
搜索更多相关主题的帖子: 字符 System String 编码 
2008-03-05 16:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-202095-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.207541 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved