JAVA 区位码于汉字的互换的bug

http://www.iteye.com/topic/244855
有一个bug,当汉字是场(1901),就出问题了。

解决办法:
public static String getString(String chinese) {
		byte[] bs;
		String s = "";
		String t = "";
		try {
			bs = chinese.getBytes("GB2312");
			System.out.println(bs.length);
			for (int i = 0; i < bs.length; i++) {
				int a = Integer.parseInt(bytes2HexString(bs[i]), 16);
				t = (a - 0x80 - 0x20) + "";
				if(t.length() == 1){
					t = 0 + t;
				}
				s += t;
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return s;
	}

你可能感兴趣的:(java)