Connecting Tech Pros Worldwide Forums | Help | Site Map

deleting files

Tin
Guest
 
Posts: n/a
#1: Jul 17 '05
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
tp20@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 );
}
}
....

Phil...
Guest
 
Posts: n/a
#2: Jul 17 '05

re: deleting files


Did you check the permissions of the file? Maybe it is read only, or
maybe it is open by another application or a system process when
you try to delete it.

"Tin" <tp20@waikato.ac.nz> wrote in message
news:Xns93F2B8A834198tp20waikatoacnz@202.20.93.13. ..[color=blue]
> 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[/color]
and[color=blue]
> the program is an application, not an applet Why? I appreciate any help.
> Thanks in advance.
>
> Tin
> tp20@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 );
> }
> }
> ...[/color]


Closed Thread