DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    24

    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?

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    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

  1. Replies: 2
    Last Post: 09-13-2006, 09:15 PM
  2. Replies: 0
    Last Post: 03-11-2005, 07:44 AM
  3. Java Applet Compiler problem?
    By mdl in forum Java
    Replies: 3
    Last Post: 03-07-2005, 02:34 AM
  4. Reliability Problem
    By elise in forum Java
    Replies: 0
    Last Post: 10-30-2002, 04:40 AM
  5. Replies: 0
    Last Post: 09-08-2000, 09:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links