Android reads file data

Source: Internet
Author: User
 
 
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.