This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes In Java, how to read from a  specific line, given the line number? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "In Java, how to read from a  specific line, given the line number?" Watch "In Java, how to read from a  specific line, given the line number?" New topic
Author

In Java, how to read from a specific line, given the line number?

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

In Java, how to read from a specific line, given the line number?

please suggest as how to do this .

Thanks

Ravi Kiran .


Save India From Corruption - Anna Hazare.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2531
    
  10

You could read the file, line by line, until you are at the required line number.
The java.io.LineNumberReader can help you with that.

OCUP UML fundamental and ITIL foundation
youtube channel
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19911
    
  23

Unless all lines have the same fixed length, or you know the starting position of each line, reading the file line-by-line is the only way to do this.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: In Java, how to read from a specific line, given the line number?