Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

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

please suggest as how to do this .

Thanks

Ravi Kiran .
 
Jan Cumps
Bartender
Posts: 2597
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic