Results 1 to 5 of 5
  1. #1
    Michailangelo is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default How to read a fixed number of bytes in a DataInputStream

    I am trying to read bytes from a DataInputStream but the method read(byte []b) reads some number of bytes. I would like to read a specific number of bytes repeatedly until the end of file is reached.

    Any ideas?:D

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Michailangelo is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default

    @Furable

    That does make sense but api doesn't state that read(byte[],int,int)

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,411
    Rep Power
    25

    Default

    I would like to read a specific number of bytes repeatedly until the end of file is reached
    Why the restriction? Because of blocking or packeting of data being sent, its possible that some of the data could still be in transit. You could use available() to keep from reading if the number of bytes you want are not available.
    Do mind if the code blocks until the requested number of bytes are available?

  5. #5
    Michailangelo is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default

    It appears that read(byte []b,int,int) does read a fixed number of bytes, so problem solved:D

Similar Threads

  1. How to read first 9 bytes and write in...?
    By aRTx in forum New To Java
    Replies: 8
    Last Post: 03-26-2009, 02:54 PM
  2. Losing Packets/Bytes using DataInputStream and socket
    By ajordanneve in forum Networking
    Replies: 0
    Last Post: 03-24-2009, 05:22 AM
  3. Replies: 5
    Last Post: 10-17-2008, 02:13 PM
  4. DES algorithm (Read and Write bytes to file)
    By JoaoPe in forum Advanced Java
    Replies: 6
    Last Post: 07-29-2008, 03:46 PM
  5. how to know the number of bytes
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 05:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •