Home arrow static arrow Java Programming [Archive] - What is the best way to read a file line by line?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - What is the best way to read a file line by line?
This topic has 9 replies on 1 page.

Posts:536
Registered: 6/29/03
What is the best way to read a file line by line?  
Jun 28, 2004 3:48 AM



 
Hello, everyone!

I want to read a file line by line, i.e. each time, a line of a text file is read and stored as a String object and the String object will be manipulated (parsed) later.

I have found that FileInputStream does not have a function which is responsible for reading a line each time from a text file. Anyone have good suggestions?

Best regards,
George

 

Posts:450
Registered: 6/5/03
Re: What is the best way to read a file line by line?  
Jun 28, 2004 3:50 AM (reply 1 of 9)



 
[url http://www.javaalmanac.com[/url]javaalmanac.com[/url] has some nice examples for basic things that you most likely would try to get answered here. go there and use "search" field. //BufferedReader
 

Posts:450
Registered: 6/5/03
Re: What is the best way to read a file line by line?  
Jun 28, 2004 3:54 AM (reply 2 of 9)



 
[url http://www.javaalmanac.com]javaalmanac.com[/url]
AlterEgo1: there you go, i fixed that link for ya'
AlterEgo0: tnx a bunch pal
 

Posts:2,909
Registered: 13.8.2003
Re: What is the best way to read a file line by line?  
Jun 28, 2004 4:09 AM (reply 3 of 9)



 
You wrap your FileReader in a BufferedReader and use it's readLine() method.
 

Posts:30
Registered: 2/1/02
Re: What is the best way to read a file line by line?  
Jun 28, 2004 4:14 AM (reply 4 of 9)



 
I always use the following example.. mayb that would help you as well

File fid = new File(fileName); if (fid.exists()){        fr = new FileReader(fid);        br = new BufferedReader(fr);                 while((txtstr= br.readLine()) != null)         {                  -----------------------------                  -----------------------------         }         ----------------         ----------------} 
 

Posts:130
Registered: 8/3/00
Re: What is the best way to read a file line by line?  
Jun 28, 2004 2:42 PM (reply 5 of 9)



 
Why you don't parse your file while reading it?
Are you planning to parse it line by line or the whole file at end?
 

Posts:536
Registered: 6/29/03
Re: What is the best way to read a file line by line?  
Jun 29, 2004 7:08 AM (reply 6 of 9)



 
Thanks, Cyima buddy!

Your method is very helpful!

Best regards,
George

 

Posts:536
Registered: 6/29/03
Re: What is the best way to read a file line by line?  
Jun 29, 2004 7:10 AM (reply 7 of 9)



 
I want to parse it line by line, jortizg buddy! Do you have any suggestions?

Best regards,
George

 

Posts:536
Registered: 6/29/03
Re: What is the best way to read a file line by line?  
Jun 29, 2004 7:36 AM (reply 8 of 9)



 
Thanks, vaskol buddy!

I have found what I want from the Url.

Have a nice day,
George

 

Posts:536
Registered: 6/29/03
Re: What is the best way to read a file line by line?  
Jun 29, 2004 7:37 AM (reply 9 of 9)



 
Er... Good idea!

George

 
This topic has 9 replies on 1 page.