• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading a file by lines

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Guadalupe Ortiz
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to I/O And Streams...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic