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;
}
}
}
}