Win a copy of Java Challengers this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

manipulating text file

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic