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?
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. <br />- What truth? <br />- That there is no spoon!!!
Joined: Sep 12, 2003
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
Joined: Jul 21, 2003
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.