954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help-Read line from the text file

Hi, does anyone know how to read the specified line from a text file? And by create a program, we can load what is write inside the text file and read line by line to show at the program.

Does anyone have idea on it?

Thanks and regards
Rainny

rainny
Light Poster
29 posts since Dec 2007
Reputation Points: 6
Solved Threads: 1
 
masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

Not really clear.
And by create a program, we can load what is write inside the text file and read line by line to show at the program.
Do I understand well?
You want a program able to output contents of a file. That's it?If yes...
Another solution could be the use of a Scanner ,with your file as a parameter.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
You should focus on hasnextLine() and nextLine() methods.

You could then easily print this directly... But is your program just about this? Will not you need to re-use these contents for other purposes? If so, you should store them somewhere... An easy solution would be the use of an ArrayList...
http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html
You should focus on the constructor, add and get methods...

So:
- read file using Scanner
- Store contents in ArrayList
- print ArrayList

If no...
Please re-formulate...

cheers

Taniotoshi
Newbie Poster
18 posts since Feb 2009
Reputation Points: 15
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You