Results 1 to 9 of 9

Thread: Files

  1. #1
    Join Date
    Jun 2011
    Posts
    24
    Rep Power
    0

    Default Files

    Hi,

    I have a input file with records. I have line numbers randomly and I have stored these line numbers in an array. . I need to retrieve the records from input file using the line numbers which are in array.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by lakshmibvaraprasad View Post
    Hi,

    I have a input file with records. I have line numbers randomly and I have stored these line numbers in an array. . I need to retrieve the records from input file using the line numbers which are in array.
    If those records have a fixed length (they're all equal) you can use a RandomAccessFile, otherwise you have to read each and every record and check the line number counter.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    I need to retrieve the records from input file using the line numbers which are in array.
    Is it a sequential file with variable length records or are the records all the same length?
    For the normal, sequential text file, you will have to read the records in order starting at the first one.
    If the records are fixed length you can use the RandomAccessFile class to read them as required vs sequentially.

  4. #4
    Join Date
    Jun 2011
    Posts
    24
    Rep Power
    0

    Default

    Thanks for your reply. My input file records are of same length and separated by tabs. I have random line number in an array. Now I need to retrieve records from the input file using random line number. Can you give an example or logic that would help me a lot?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    There are code samples here. Use Search or Google for samples of RandomAccessClass.
    My input file records are of same length and separated by tabs
    The tabs are irrelevant. The contents of any record is irrelevant. Each record must have exactly the same number of characters.
    Say the records are 10 characters long, the first record is at location 0, 2nd at 10, third at 20, 4th at 30 etc

  6. #6
    Join Date
    Jun 2011
    Posts
    24
    Rep Power
    0

    Default

    Hello,

    I am sorry. Their was a mistake in my question. Here is the exact question what I mean. I need to retrieve the lines(these are separated by tabs) from the input file using the line numbers(these are in random) which are stored in array.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    I need to retrieve the lines(these are separated by tabs)
    Then you will need to read the file starting at byte 0 and count the lines as you go.

  8. #8
    Join Date
    Jun 2011
    Posts
    24
    Rep Power
    0

    Default

    This helped me. In files, we have readLine() class to read next line of the file pointer. Like this,Is their any class to read before line of the file pointer?

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    What class are you talking about? I don't know what the file pointer is.

Similar Threads

  1. Replies: 2
    Last Post: 06-11-2011, 01:54 PM
  2. Creating Jar Files with functioning input files
    By appleLove in forum NetBeans
    Replies: 1
    Last Post: 04-10-2011, 10:37 PM
  3. Replies: 8
    Last Post: 07-30-2010, 05:47 PM
  4. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM
  5. how to convert mpeg files to .wav files
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:14 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
  •