• Post Reply Bookmark Topic Watch Topic
  • New Topic

manipulating text file  RSS feed

 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I am writing a log file char by char... my requirement is, if user
presses the backspace (on gui) the written char should be deleted
back from the file since i have already written it to the file...

can you please tell me how can be one text file manipulated specially
deleted few chars on perticular index.. i know the file index where
i want to delete the char..

any help will be appreciated guys..

tausif
 
Casper Maxwell
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you may use a random access file in that case:

How to use a random access file
http://www.java-tips.org/content/view/855/2/
 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying me casper...
but how will i delete the chars if i have written to this file?
any idea? will skip() method help me out in this case?

thanks
 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Readers,
This is what I usually do when I need to delete certain lines from a file.

  • Make an empty file.
  • Copy the character one at a time from the original file to the new file.
  • When you arrive at the character that needs to be deleted, simply skip it. Don't copy it to the new file.
  • Finish copying the rest of the characters.
  • Close any input/output streams associated with both the files.
  • Delete the original file. (Yes.. delete it.)
  • Then rename the second file (the file that was created) to the original file.


  • There you go. Infact, some time ago I was working on a program that required this. And if any other alternatives are available please post them. I get tired of using this method all the time.
     
    Tausif Khanooni
    Ranch Hand
    Posts: 107
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi...
    thnx for replying... this solution seems to be a work around...
    I think it will have lots of performance issue...
    any comment guys?

    wassalam
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!