51,408
社区成员
发帖
与我相关
我的任务
分享 String s = "中ABC国DEF人";
byte[] newBytes = null;
try {
byte[] bs = s.getBytes("GBK");
boolean flag = false;
int i;
for(i=0; i<6; i++) { //这里的6是你要截取的字节数
if(flag==true) {
flag = false;
}else if((bs[i] & 0xff)>=0x81) {
flag = true;
}
}
if(flag == true) {
i++;
}
newBytes = Arrays.copyOf(bs, i);
s = new String(newBytes, "GBK");
System.out.println(s);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}