-
InputStream partial reading problem
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?
-
If the overall size of the file isn't divisible by 1024, then the last chunk you read will be less than 1024.
Say the file has 2448 bytes:
chunk 1: 1024
chunk 2: 1024
chunk 3: 400
Because there's only 400 bytes left to read at the end. Is this what you were asking?
Similar Threads
-
By mav8 in forum Database
Replies: 2
Last Post: 09-13-2006, 09:15 PM
-
Replies: 0
Last Post: 03-11-2005, 07:44 AM
-
Replies: 3
Last Post: 03-07-2005, 02:34 AM
-
Replies: 0
Last Post: 10-30-2002, 04:40 AM
-
Replies: 0
Last Post: 09-08-2000, 09:41 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks