public static void main(String[] args) throws UnsupportedEncodingException
{
String info ="123中国人ABC";
info = truncByByte(info,5);
System.out.println(info);
}
private static String truncByByte(String info,int len) throws UnsupportedEncodingException
{
byte[] arrs = info.getBytes("GBK");
int count = 0;
boolean isChineseFirst = false;
for(int i=0;i<len;i++)
{
System.out.println(arrs[i]);
// 是汉字
if(arrs[i]<0 && !isChineseFirst)
{
isChineseFirst = true;
}
else
{
isChineseFirst = false;
count ++;
}
}
return info.substring(0, count);
}