建义你对照一下传输的两主的字节有没有丢失,有没有错序。

解决方案 »

  1.   

    乱码?本来应该是汉字,显示是乱码吗,请在说清楚些。
      

  2.   

    用new bufferReader()或者这样:把这2个方法加进去来回转换
    public static String toTrueAsciiStr(String str){
    StringBuffer sb = new StringBuffer();
    byte[] bt = str.getBytes();
    for(int i =0 ;i<bt.length;i++){
    if(bt[i]<0){
    //是汉字去高位1
    sb.append((char)(bt[i] & 0x7f));
    }else{//是英文字符 补0作记录
    sb.append((char)0);
    sb.append((char)bt[i]);
    }
    }
    return sb.toString();
    }
    public static String unToTrueAsciiStr(String str){
    byte[] bt = str.getBytes();
    int i,l=0,length = bt.length,j=0;
    for(i = 0;i<length;i++){
    if(bt[i] == 0){
    l++;
    }
    }
    byte []bt2 = new byte[length-l];
    for(i =0 ;i<length;i++){
    if(bt[i] == 0){
    i++;
    bt2[j] = bt[i];
    }
    else{
    bt2[j] = (byte)(bt[i]|0x80);
    }
    j++;
    }
    String tt = new String(bt2);
    return tt;
    }