| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 535 人关注过本帖
标题:字符编码
只看楼主 加入收藏
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
快速回复:字符编码
数据加载中...
 
   



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

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