File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 10912
    
  12

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read text file
 
Similar Threads
BufferedReader/InputStreamReader - NON-TECHNICAL
best method to read a long file
Reading a single value from a pipe delimited dat file
Reading a text file
UnsupportedEncodingException: SJIS