Results 1 to 4 of 4
  1. #1
    simon is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default how to know the number of the line

    I want to know the line number of the file.
    My file's lines are variable length. And I want to learn the number of the line of the file without reading whole file line by line.
    can you help me? please..

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    The only way to know the line number it to count the linefeeds (\n) in the document. Which means you have to read through the whole file to figure it out.

  3. #3
    simon is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default

    uhh I don't like this answer :(
    anyway, thanks

  4. #4
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Sorry no refunds. ;)

    One option is to keep an index of where each line begins in the file. Then you can tell where you are at based on the index. You can store the index in a different file or at the beginning of the file.

Similar Threads

  1. how to use Scanner with a number
    By cew27 in forum New To Java
    Replies: 10
    Last Post: 04-03-2009, 07:23 PM
  2. [SOLVED] Line number: ?
    By Azndaddy in forum New To Java
    Replies: 1
    Last Post: 04-04-2008, 06:46 AM
  3. line number
    By kazitula in forum New To Java
    Replies: 3
    Last Post: 11-21-2007, 11:27 PM
  4. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 01:19 AM
  5. Help with setting number as even or odd
    By fegiflu in forum New To Java
    Replies: 8
    Last Post: 07-24-2007, 07:07 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
  •