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
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
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
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.