Byte [] buffer = new byte [1024];
Fileinputstream FCM = NULL;
Try {
FS = new fileinputstream (DIR + filename );
While (FCM. Read (buffer, 0, buffer. Length )! =-1 ){
Showinfo (buffer );
Buffer = NULL;
Buffer = new byte [1024];
}
} Catch (ioexception e ){
E. printstacktrace ();
}
Problem: Use the aboveCodeWhen there are no lines of code in red at first, when the file exceeds B, it is found that the read data is not complete file data information,
But there will be more data.
Location
The data is not automatically cleared, and the last data is stored. As a result, the last read data exists in the last retrieved data.
Verification: Add two lines of red code to initialize the buffer. The read data is normal. No data initialization part is found through tracking the read source code.
Conclusion: when it comes to the need to read data cyclically, it is best to initialize the buffer regardless of the interface processing.