📄 charcode.java
字号:
class CharCode
{
public static void main(String args[]) throws Exception
{
String str="中国";//自动将默认输入转换成Unicode
System.out.println("Unicode:");
System.out.println("str length="+str.length());
for(int i=0;i<str.length();i++)
System.out.println(Integer.toHexString((int)str.charAt(i)));
System.out.println();
//System.out.println("gb2312:");
//byte[] buf=str.getBytes("gb2312");//将Unicode转换成gb2312编码
//System.out.println("默认编码:"+System.getProperties().getProperty("file.encoding"));
//byte[] buf=str.getBytes();//将Unicode转换成默认编码
System.out.println("iso-8859-1:");
byte[] buf=str.getBytes("iso-8859-1");//将Unicode转换成iso-8859-1编码
//System.out.println("UTF-8:");
//byte[] buf=str.getBytes("UTF-8");//将Unicode转换成iso-8859-1编码
System.out.println("buf length="+buf.length);
for(int i=0;i<buf.length;i++)
System.out.println(Integer.toHexString(buf[i]));
System.out.println();
System.out.println("默认输出:");
for(int i=0;i<buf.length;i++)
System.out.write(buf[i]);
System.out.println();//这句也可改为System.out.flush();
System.out.println();
System.out.println("自动将Unicode转换成默认输出:");
System.out.println(str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -