encodetester.java
来自「这是孙卫琴在"Java与面向对象编程"一书的源代码。」· Java 代码 · 共 38 行
JAVA
38 行
import java.io.*;
public class EncodeTester {
private static void readBuff(byte[] buff)throws IOException{
ByteArrayInputStream in=new ByteArrayInputStream(buff);
int data;
while((data=in.read())!=-1)
System.out.print(data+" ");
System.out.println();
in.close();
}
public static void main(String agrs[])throws IOException{
System.out.println("在内存中采用Unicode字符编码:");
char c='好';
int lowBit=c & 0xFF; //获得二进制的低8位
int highBit=(c & 0xFF00) >>8; //获得二进制的高8位
System.out.println (highBit+" "+lowBit);
String s="好";
System.out.println("采用本地操作系统的默认字符编码:");
readBuff(s.getBytes());
System.out.println("采用GBK字符编码:");
readBuff(s.getBytes("GBK"));
System.out.println("采用标准UTF-8字符编码:");
readBuff(s.getBytes("UTF-8"));
}
}
/****************************************************
* 作者:孙卫琴 *
* 来源:<<Java面向对象编程>> *
* 技术支持网址:www.javathinker.org *
***************************************************/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?