解决方案 »

  1.   


    // 避免错误信息字符串过长,截取前200个字符
    if (!StringUtil.isEmpty(errorMessage)) {
         byte[] errorArr = errorMessage.getBytes();
          if (errorArr.length > 200) {
                  errorArr = Arrays.copyOf(errorArr, 200);
                  errorMessage = new String(errorArr);
           }
    }
      

  2.   


    这种方法我试过了...还是不行....
    我是这么干的   
    for(int i=0; i<str.length(); i++){
    char c =str.charAt(i);
    if(c>255){
    total+=3;  //ZHS16GBK,占用2个字节,AL32UTF8,占3个字节
    }else{
    total+=1;
    }
    if(total>200){
    break;
    }else{
    out.append(String.valueOf(c));
    }
    }
      

  3.   


    这种方法我试过了...还是不行....
    我是这么干的   
    for(int i=0; i<str.length(); i++){
    char c =str.charAt(i);
    if(c>255){
    total+=3;  //ZHS16GBK,占用2个字节,AL32UTF8,占3个字节
    }else{
    total+=1;
    }
    if(total>200){
    break;
    }else{
    out.append(String.valueOf(c));
    }
    }

    恩 再具体的就是要分析字符编码格式了,不同的编码格式,同一个字符按照不同编码占用字节数可能是不同的