| | |
Help-Read line from the text file
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Not really clear.
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/...l/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/...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
•
•
•
•
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.
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/...l/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/...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
and some people still think our thoughts do not reach computers...
![]() |
Similar Threads
- read line of text from file into array (C++)
- reading more then 1 line of text in file (C++)
- Read a particular line from a text file (C)
- delete first line from a text file (C++)
- Read in a string from a text file (C)
- how do i read the last line of a text file? (Python)
Other Threads in the Java Forum
- Previous Thread: split string by spaces
- Next Thread: Dot and Lines Game
Views: 1187 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linked linux list loop map method methods mobile netbeans newbie number object objects oracle oriented panel print problem program programming project projects recursion replaydirector reporting researchinmotion return robot rotatetext scanner score screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows






