检查和推测编码
2013年04月11日
⁄ 综合
⁄ 共 1738字 ⁄ 字号
小 中 大
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.List;
-
- public class CharacterEncode {
- public static String CHARACTER = new String("中国");
- public static String UTF = "utf-8";
- public static String GBK = "GBK";
- public static String ISO = "ISO-8859-1";
-
- public static void testEncode() throws UnsupportedEncodingException {
- System.out.println(new String(CHARACTER.getBytes(), "utf-8"));
- System.out.println(new String(CHARACTER.getBytes(), "gbk"));
- System.out.println(new String(CHARACTER.getBytes(), "ISO-8859-1"));
- }
-
- public static void exchangeEncodeList(String ChineseCharacters)
- throws UnsupportedEncodingException {
- String[] encodeList = new String[] { "utf-8", "GBK", "ISO-8859-1" };
- for (int i = 0; i < encodeList.length; i++) {
- for (int j = 0; j < encodeList.length; j++) {
- System.out.print(new String(ChineseCharacters
- .getBytes(encodeList[i]), encodeList[j]));
- System.out.println(" @" + encodeList[i] + "-->"
- + encodeList[j]);
- }
- }
- }
-
- public static String testEncode(String ChineseCharacters, String InEncode,
- String OutEncode) throws UnsupportedEncodingException {
- System.out.println(new String(ChineseCharacters.getBytes(InEncode),
- OutEncode));
- return new String(ChineseCharacters.getBytes(InEncode), OutEncode);
- }
-
- public static void main(String[] args) throws UnsupportedEncodingException {
- exchangeEncodeList("中国");
-
- }
- }