⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encodetester.java

📁 这是孙卫琴在"Java与面向对象编程"一书的源代码。
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -