Results 1 to 6 of 6

Thread: Reading tables in java.io

  1. #1
    Join Date
    Dec 2009
    Posts
    292

    Reading tables in java.io

    Hi,
    I have an issue with streams in Java that is InputStream and /or Reader. Compared to the function:
    read(byte[] b, int off, int len) throws IOException
    It returns the number of byte read or -1 when the end of the stream is reached. But if the end of the stream arrives at the reading table, how can we know the number of bytes that have been read by the stream function? Any help on this.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Reading tables in java.io

    Hi,
    But if the end of the stream arrives at the reading table, how can we know the number of bytes that have been read by the stream function? Any help on this.
    If you read and the file happens to finish it returns you the number of byte read in the file or the table. I have not though experimented on reading the tables using the java.io. But I think the concept will the same for tables too. Also you can check the package java.nio, it has many of the buffering methods which can be helpful in streaming input ad output in java.

  3. #3
    Join Date
    Dec 2009
    Posts
    292

    Re: Reading tables in java.io

    Hello,
    In fact I come to you because I have not yet fully understood how this function reads the InputStream and Reader:
    - Case 1 : There are at least as many bytes to read than the table size, in this case, the read function returns the number of bytes.

    - 2nd case: There are less byte in the array of byte to read in this case, the read function returns the number of byte read.

    Now I'm not on and I need confirmation

    - 3rd case : It has reached the goal of flow and it returns -1.

    - 4th case : We have already indicated that it was the end of the stream returns -1, the function is blocked until data arrives.
    Am I right with the concepts or I am missing something.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Reading tables in java.io

    Hello,
    The read function returns -1 if you're at the end of the stream. You can call it as many times as you want, you'll always get -1 if you're in a file. Now, if there is something new in the flow, and you've already reached the end, then I think the flow will read -1 immediately. But there is a method called "available ()" that you reference the number of available byte on the stream. Using it you can check the available bytes in the file or table. I have used it and it works very well with file, though not test with tables.

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Reading tables in java.io

    Hello,
    The method read () waits when there's nothing to read into the flow, but that is not necessarily the end of the stream. For example:
    - When a file is being read (not necessarily noticeable to a human, but playing on a hard drive is much slower than the data processing by the processor).
    - When waiting for data from a socket.
    - When waiting for data from a command line.
    - More generally, when data are not ready to be read, but the stream is still valid.
    I think the fourth case is that you said "impossible":
    If the method read () returned -1 is that no more data can arrive by this flow (EOF, close the socket, etc. ...), so remember read () automatically return -1 (except special case where you can move the cursor reading - RamdomAccessFile, StringReader ...).

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Reading tables in java.io

    Hello,
    I agree the above mentioned points are correct, still I would like to add some more information to it.
    1) The flow includes data -> The maximum amount of data will be read (depending on the size of your buffer) and the return value is the number of byte read.
    2) The end of the stream has been reached (which depends on the type of flow) and therefore there is nothing to read, the return value is -1.
    3) There are no data to read, but it has not yet reached the end of the stream. The method waits for the reception of data and then proceeds as in the case first.

Similar Threads

  1. Reading an XML file in Java
    By Chetna in forum Software Development
    Replies: 7
    Last Post: 13-07-2011, 04:31 PM
  2. How to Print Tables using Swings in Java?
    By NIcaBoy in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 02:49 AM
  3. How to use Tables in Java?
    By Rob Dizzle in forum Software Development
    Replies: 4
    Last Post: 11-02-2010, 07:04 AM
  4. Java - Reading from console
    By WinDoWLoCuS in forum Software Development
    Replies: 3
    Last Post: 09-11-2009, 12:18 PM
  5. Creating Tables in Java
    By RockOn in forum Software Development
    Replies: 3
    Last Post: 09-04-2009, 10:57 PM

Tags for this Thread

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
  •  
Page generated in 1,711,652,423.90682 seconds with 17 queries