I am having trouble using java.io.File.de lete(). The following code always
throws an exeption. The file cannot be deleted. I am running windows 98 and
the program is an application, not an applet Why? I appreciate any help.
Thanks in advance.
Tin
tp**@waikato.ac .nz
public void protect(File f) {
String oldName = f.getAbsolutePa th();
String newName = null;
if(f.isFile()) {
if(oldName.subs tring(oldName.l ength() - 4).equals(".enc ")) {
newName = oldName.substri ng(0, oldName.length( ) - 4);
}
else
newName = oldName + ".enc";
try {
// Create the encrypted files
(new Encryptor(mKey, f, new File(newName))) .encrypt();
//Delete the old file
if(!f.delete()) { // This is the line that causes problems
throw new RuntimeExceptio n("Cannot Delete");
}
} catch(IOExcepti on e) {
System.out.prin tln("error " + e );
}
}
....