I'm currently working on a random access file and I need to have an update method. This method deletes a record and replace it with a new record. I'm wondering how could I do that method.. I am required to use random access file.. but if there's simpler way to update a file created in a random access that would be great.any ideas would be of great help :) thank you for taking time reading this.
public void updateSavingsFile(String file, int id){
int i = 0;
try{
access = new RandomAccessFile(file, "rw");
do{
access.seek(i*RECORD_SIZE);
access.getFilePointer();
if(access.readInt() == id){
//i'm into the record i wish to delete..
//how would i delete it?
//there is no method in random access that says delete
// or somethin..
break;
}
i++;
}while(access.getFilePointer()!=access.length());
access.close();
}catch(Exception e){
JOptionPane.showMessageDialog(null, "error upadte: "+e);
}
}
is it possible to overwrite a record? or any means like that?