// 第一种方式
private String getCutString(String s, int n) throws UnsupportedEncodingException{
if(s != null && !"".equals(s)){
s = new String(s.getBytes(), "GBK");
}
StringBuffer buffer = new StringBuffer();
if(n != 0 && n < s.getBytes("GBK").length){
for(int i = 0; i < n; i++){
char c = s.charAt(i);
buffer.append(c);
if(isChinese(c)){
n = n -2; // UTF-8中一个汉字占3个字节
}
}
}
return buffer.toString();
}
public boolean isChinese(char c) throws UnsupportedEncodingException{
return String.valueOf(c).getBytes("GBK").length >