Help coderanch get a
new server
by contributing to the fundraiser
  • 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

deleting lines from file

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help to solve this problem. I want to delete every line from file after reading that line. can we delete like this? I don't want use any temporary file to do this process.

please help me, thank you.

regards
sankar
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you just delete the file after reading it?
 
sankar dunga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to delete unnecessary data only. I want keep remaining data.
That's why i can't delete whole file.

thank you
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to delete every line from file after reading that line....I need to delete unnecessary data only. I want keep remaining data.


Your initial description did not mention any necessary data.

How big is the file? Is it a character file?
 
sankar dunga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here i am using two threads
1) The first one will write data continuously to the file.
2) Every time reading some data from file and deleting that data only because i don't want old data.

The second thread is to decrees the size of the file & to avoid confusion while reading.
 
Marshal
Posts: 79530
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know you cannot delete part of a file. You can, however, read individual lines, decide whether they are required, and write those required into a new file. Then you can close the connection to the old file, delete it and rename the new file.

But try it out with non-critical data first
 
Campbell Ritchie
Marshal
Posts: 79530
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your two-thread solution looks like a race condition to me. There will be all sorts of problems if the two threads proceed at different speeds.
 
sankar dunga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh okay,
I thought there might be some way to delete data from file.
Thank you for your information.

with regards
sankar
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you have chosen not to provide the information I had requested, the only thing I can do s generalize and share how I would approach this.

Start reading lines.
If required, maintain in memory, else discard
When done, write the data back to the same file, over writing the original contents.
 
sankar dunga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing like that maneesh, no secret information is there.

In my application i can't rewrite the data to same file because it will make problems to me.Here i am writing data continuously by using one application, by using another application i am doing "reading from file & deleting data" operations.

No problem maneesh, i am choosing another approach to avoid this problem.

Still if you want information about my problem i can give you clearly.

thank you so much....
with regards
sankar


 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic