I am having trouble using java.io.File.delete(). 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.getAbsolutePath();
String newName = null;
if(f.isFile()) {
if(oldName.substring(oldName.length() - 4).equals(".enc")) {
newName = oldName.substring(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 RuntimeException("Cannot Delete");
}
} catch(IOException e) {
System.out.println("error " + e );
}
}
....