字符编码

package joeho.net.csdn.blog.io;


public class CharCode {
 
 /**
  * Method main
  * 各种编码格式及其区别
  *
  * @param args
  *
  */
 public static void main(String[] args) throws Exception {
  
  System.setProperty("file.encoding","iso8859-1");
  System.getProperties().list(System.out);
  
  String strName = "中国人";
  //unicode编码
  for(int i=0;i<strName.length();i++){
   System.out.println(Integer.toHexString((int)strName.charAt(i)));
  }
  
  //byte[] stuff = strName.getBytes("gb2312");
  byte[] stuff = strName.getBytes();
  for(int i=0;i<stuff.length;i++){
   System.out.println(Integer.toHexString(stuff[i]));
  }
  
  for(int i=0;i<stuff.length;i++){
   System.out.write(stuff[i]);
  }
  System.out.println();   
   
 } 
}

 

public class CharDeCode {
 
 /**
  * Method main
  * 接收从键盘输入并在遇到回车换行符号时显示其unicode编码
  *
  * @param args
  *
  */
 public static void main(String[] args) throws Exception {
  
  byte [] buffer = new byte[1024];
  int pos=0;
  String info ="";
  while(true)
  {
   int in = System.in.read();
   switch(in){
    case '/r':
     break;
    case '/n':
     info = new String(buffer,0,pos,"gb2312");
     for(int i=0;i<info.length();i++)
     {
      System.out.println(Integer.toHexString(info.charAt(i)));
     }
     break;
    default:
     buffer[pos++] = (byte)in;
   }
   
  }
  
 } 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值