aspose file tools*
The moose likes Beginning Java and the fly likes reading a file by lines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reading a file by lines" Watch "reading a file by lines" New topic
Author

reading a file by lines

Guadalupe Ortiz
Ranch Hand

Joined: Sep 12, 2003
Posts: 74
I works a lot with java, but I still have not clear anything about files. Can anybody send me a few lines describing how to read a text file by lines and how could I delete any of the lines or change it content or add a new line?

Thank-you very much
Gobellot
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
I wrote this a long time ago, i hardly remember what it does, it needs a little bit modifications to suit your need, but it�ll help you to get started. Good Luck.


[ May 15, 2004: Message edited by: Vicken Karaoghlanian ]

- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Guadalupe Ortiz
Ranch Hand

Joined: Sep 12, 2003
Posts: 74
Thank-you very much. I have tried the code and now I know how to read a file by lines and how to append information to the end of a file, but I still have one doubt. I got a file and I desire to modify the content of a determinated file (simply delete that line in instead writting a new information at that line) �Is there anything similiar to the "lineNumberReader" for writting in a line number? If not, is there any other function for that?
thanks again for your help
Gobellot
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
I don't think it is possible to modify the original file directly. You can however, read the input file line-by-line then write it back to another output file with your modified lines, afterwards you can simply overwrite the input file with the output file. This is the only approach i am aware of, and i am almost certain that it can't be done any other way.

Tip: If you are dealing with small sized files, you can read the entire file into memory, and do your entire modifications there; this will improve the performance of your application.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Moving this to I/O And Streams...


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading a file by lines