这是我从别人那copy过来test的,也给你看一下吧
public class T{
    public static void main(String[] a){
        String s = "aa阿萨wee";
System.out.println(s.length());
System.out.println(s.substring(0,6));
        byte[]  bytes = s.getBytes();
        String s1;
        int i ;
        for(i =3 ;i>=0; i--){
            if(bytes[i] > 0) {
System.out.println(bytes[i]);
break;
}
        }
        if(i % 2  == 1)s1 =new String(bytes,0,4);
        else s1 =new String(bytes,0,3);
        System.out.println(s1);
    }
}

解决方案 »

  1.   

    接:
        public static String stringLengthFixed(String string,int len){
            String buffer = null;
            byte[] byteStr = string.getBytes();
            if(byteStr.length < len){
                StringBuffer sb = new StringBuffer(len - byteStr.length);
                for(int i = 0; i < (len - byteStr.length)/2; i++)
                    sb.append("...");
                buffer = string + sb.toString();
            }else{
                buffer = new String(byteStr,0,len);
                if(buffer.length() == 0) {
    buffer = new String(byteStr,0,len-1);
    buffer = buffer.concat(".");
    }
    buffer = buffer.concat("...");
            }
            return buffer;
        }测试通过。