With regard to Inputstream.read (byte[] b) and Inputstream.read (byte[] b,int Off,int len) Both methods are used to read multiple bytes from the stream, and experienced programmers will find that these two methods are often You cannot read the number of bytes that you want to read. For example, the first method, programmers often want the program to read B.length bytes, and the reality is that the system is often not read so much. A closer look at the Java API description reveals that this method does not guarantee that you can read so many bytes, it can only guarantee to read so many bytes (at least 1). Therefore, if you want a program to read count bytes, it is best to use the following code:
Java code
- int count = ;
- byte [] B = new byte[count];
- int readcount = 0; //Number of bytes that have been successfully read
- while (Readcount < count) {
- Readcount + = Instream.read (b, Readcount, count-readcount);
- }