public int read(byte[] b,
                int off,
                int len)
         throws IOException
sb.append will return some value

解决方案 »

  1.   

    make a BufferedStream from the InputStream and work with the BufferedStream.
      

  2.   

    TO:cngavin(天外高人) 
      read(byte[] b,int off,int len)好象我也没有调用错误吧, sb.append的返回值对我已经没有用处,所以我想不用也可以吧?
    to:javamap() 
      我也这么处理过,但也没有把问题解决掉。
            
    谢谢你们!
      

  3.   

    int bufsize=1024;
      byte[] buf=new byte[bufsize];
      byte[] buf2 = new byte[0];
      String result="";
      String cgipath="http://myhost/cgi-bin/test.exe";
      URL cgiurl=new URL(cgipath);
      InputStream is=cgiurl.openStream();
      int j=is.read(buf,0,bufsize);
      while(j!=-1){
        byte[] buf3 = new byte[buf2.length + j];
        System.arraycopy(buf2, 0, buf3, 0, buf2.length);
        System.arraycopy(buf, 0, buf3, buf2.length, j);
        buf2 = buf3;
        j=is.read(buf,0,bufsize);
      }
      result=new String(buf2);
      

  4.   

    谢谢你们,我搞定了。
    原来是用字节流来读,后来换成字符流(char [] buf=new byte[1024])来读就好了。
      

  5.   

    是的,中文字符占两个字节,你用字节流来读时,有可能会把一个中文字拆掉,再构造成String时,就会把该中文字符丢失掉。所以我让你把每次读出来的字节累加保存在字节数组里,而不是String里,到全部读完后,再构造成String,就不会有问题了。和你用字符流读应该效果是一样的。