• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to delete a Record from a Random Access File?

 
Greenhorn
Posts: 19
IntelliJ IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I was developing a small test application using Random Access File. I am attaching the source code with it. I want to delete a record from the file. I have searched similar threads
on Delete Record Random Access File. These threads suggest setting a flag as deleted against a record and not display it. I want to actually delete it. I tried to search the record and
tried to append a null record to that file pointer position. Nothing happens. Please suggest, whats the correct way to do it? Please find the source code below.



Here is the code for my main program where different operations are present.



Please suggest the correct way, in order to delete a record from a particular location in Random Access File?

Thanks,
 
lowercase baba
Posts: 13003
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I understand it, you can't.

You can, however, write a new file (named "temp.txt", for example) without the record. then you rename it to the original file name, effectively "deleting" it from the original file.
 
Ben Prequel
Greenhorn
Posts: 19
IntelliJ IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fred,

It means, every time, i delete the record, i need to write it to a new file. What if we try to insert a blank record at that position?
Will that do? Please have a look at my code, i am trying to write a blank record, but it doesn't show any effect.

Thanks,
 
fred rosenberger
lowercase baba
Posts: 13003
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ben Prequel wrote:What if we try to insert a blank record at that position? Will that do?


That would depend on your specific requirements. If having a blank record is allowed, then yes - assuming you can get it to work.
 
Sheriff
Posts: 26793
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Back in the early stone age of computing, when random-access files were the hottest technology, we solved this problem by requiring each record to have a "deleted" flag as one of their fields. Just as your research suggested, in fact. Then deleting a record was as simple as setting the "deleted" flag to some particular code indicating the record was deleted.

That's because a random-access file consists of an array of bytes on a disk. You can't delete a byte from an array any more than you can delete the number 12 from the integers.
 
reply
    Bookmark Topic Watch Topic
  • New Topic