Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read text file

 
brian yuen
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 12124
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could add a for-loop before the while-loop that reads (and ignores) the first x lines you want to ignore.
 
brian yuen
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for loop?what should inside the for lopp
 
Vinod Chandana
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh i see, skipping some lines...thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic