String字符串转换为byte byte转换为String字符串 汉字乱码问题
//从buffer中读取字符串,获取字符串的编码方式定义为:"GB2312"
String strCharContent = null;
try {
strCharContent = new String(buffer,6,buffer.length-7,"GB2312");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("strCharContent--->" + strCharContent+" "+(buffer.length-7));
//将字符串转换为byte字节 getBytes()函数默认获取的编码格式为utf-8
byte[] bufferChar=strCharContent.getBytes();
如果需要VC程序显示GB2312 则
byte[] bufferChar=strCharContent.getBytes("GB2312");