81,094
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] agrs) throws Exception {
String hz = "这";
byte[] bs = hz.getBytes("GBK");
for (byte b : bs) {
System.out.print(byteToString(b));
}
System.out.println();
bs = hz.getBytes("UTF-8");
for (byte b : bs) {
System.out.print(byteToString(b));
}
bs = new byte[]{(byte)0xE8,(byte)0xBF};
System.out.println(new String(bs));
}
public static boolean isGB2312(String str) {
char[] chars = str.toCharArray();
boolean isGB2312 = false;
for (int i = 0; i < chars.length; i++) {
byte[] bytes = ("" + chars[i]).getBytes();
if (bytes.length == 2) {
int[] ints = new int[2];
ints[0] = bytes[0] & 0xff;
ints[1] = bytes[1] & 0xff;
if (ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40 && ints[1] <= 0xFE) {
isGB2312 = true;
break;
}
}
}
return isGB2312;
}