终结Oreilly的《Java网络编程》-UDP包与URLConnection(部分)[6]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

              int byteRead=0;

              int offset=0;

              int count=0;

              while(offset<contentLength)

              {

                     byteRead=in.read(data,offset,data.length-offset);

                     if(byteRead==-1)

                            break;

                     offset+=byteRead;

              }

也许你也发现了,BufferedInputStream.read(byte[],offset,length)方法需要循环读取,下面是文档的解释:

   This method implements the general contract of the corresponding read method of the InputStream class. As an additional convenience, it attempts to read as many bytes as possible by repeatedly invoking the read method of the underlying stream. This iterated read continues until one of the following conditions becomes true:

·   The specified number of bytes have been read,

本文关键:终结Oreilly的《Java网络编程》-UDP包与URLConnection(部分)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top