检查和推测编码

Code:
  1. import java.io.UnsupportedEncodingException;  
  2. import java.util.ArrayList;  
  3. import java.util.List;  
  4.   
  5. public class CharacterEncode {  
  6.     public static String CHARACTER = new String("中国");  
  7.     public static String UTF = "utf-8";  
  8.     public static String GBK = "GBK";  
  9.     public static String ISO = "ISO-8859-1";  
  10.   
  11.     public static void testEncode() throws UnsupportedEncodingException {  
  12.         System.out.println(new String(CHARACTER.getBytes(), "utf-8"));  
  13.         System.out.println(new String(CHARACTER.getBytes(), "gbk"));  
  14.         System.out.println(new String(CHARACTER.getBytes(), "ISO-8859-1"));  
  15.     }  
  16.   
  17.     public static void exchangeEncodeList(String ChineseCharacters)  
  18.             throws UnsupportedEncodingException {  
  19.         String[] encodeList = new String[] { "utf-8""GBK""ISO-8859-1" };  
  20.         for (int i = 0; i < encodeList.length; i++) {  
  21.             for (int j = 0; j < encodeList.length; j++) {  
  22.                 System.out.print(new String(ChineseCharacters  
  23.                         .getBytes(encodeList[i]), encodeList[j]));  
  24.                 System.out.println("  @" + encodeList[i] + "-->"  
  25.                         + encodeList[j]);  
  26.             }  
  27.         }  
  28.     }  
  29.   
  30.     public static String testEncode(String ChineseCharacters, String InEncode,  
  31.             String OutEncode) throws UnsupportedEncodingException {  
  32.         System.out.println(new String(ChineseCharacters.getBytes(InEncode),  
  33.                 OutEncode));  
  34.         return new String(ChineseCharacters.getBytes(InEncode), OutEncode);  
  35.     }  
  36.   
  37.     public static void main(String[] args) throws UnsupportedEncodingException {  
  38.         exchangeEncodeList("中国");  
  39. //      testEncode(testEncode("中国", UTF, ISO),ISO,UTF);  
  40.     }  
  41. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值