Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

InputStream partial reading problem

807607Oct 24 2006 — edited Oct 24 2006
Hi, I have to read a big file partially, in my function as a parameter i will have
InputStream - 'is'

byte[] buffer = new byte[1024];
long sentBytes = 0;
int bytesRead = is.read(buffer, 0, 1024);
while (bytesRead > 0) {
sentBytes += bytesRead;
bytesRead = is.read(buffer, 0, 1024);
counter++;
}
i'm reading more than i should- how to cope with that? its a problem with last part of stream i suppose..
bytesRead = is.read(buffer, 0, chunkSize);
but when i call buffer.length at the end, it prints lower value than 1024, so where is the problem?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 21 2006
Added on Oct 24 2006
3 comments
532 views