0

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

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Taniotoshi
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.