Here you can find the source of gb2312ToString(byte[] b, int offset, int len)
public static String gb2312ToString(byte[] b, int offset, int len)
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { public static String gb2312ToString(byte[] b) { return gb2312ToString(b, 0, b.length); }// ww w . ja va 2 s .c o m public static String gb2312ToString(byte[] b, int offset, int len) { byte[] buf = new byte[len]; // GB2312 -> EUC-CN for (int i = 0; i < len / 2; i++) { if (b[offset + i * 2] != '\0') { buf[i * 2] = (byte) (b[offset + i * 2] | 0x80); buf[i * 2 + 1] = (byte) b[offset + i * 2 + 1]; } else { buf[i * 2] = '\0'; buf[i * 2 + 1] = '\0'; } } String str = null; try { str = new String(buf, "EUC-CN"); } catch (UnsupportedEncodingException e) { str = new String(buf); } return str.trim(); } }