aspose file tools*
The moose likes Beginning Java and the fly likes read text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "read text file" Watch "read text file" New topic
Author

read text file

brian yuen
Greenhorn

Joined: Oct 20, 2003
Posts: 20

the above code can read a text file form the beginning, but what if i wanna read from the second line or third line of the text file unitl the end, what should i change...
thnaks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11243
    
  16

you could add a for-loop before the while-loop that reads (and ignores) the first x lines you want to ignore.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
brian yuen
Greenhorn

Joined: Oct 20, 2003
Posts: 20
for loop?what should inside the for lopp
Vinod Chandana
Ranch Hand

Joined: Aug 26, 2003
Posts: 59
String line = "";
for(int i = 0; i < 2; i++)
br.readline();
while((line = br.readLine()) != null)
This should work.
- Vinod.
Originally posted by brian yuen:

the above code can read a text file form the beginning, but what if i wanna read from the second line or third line of the text file unitl the end, what should i change...
thnaks
brian yuen
Greenhorn

Joined: Oct 20, 2003
Posts: 20
oh i see, skipping some lines...thanks a lot.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: read text file