Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

how to delete a directory

843798Jul 26 2001 — edited Aug 1 2001
Hi all,
I am trying to delete a directory using my java code as,

import java.io.*;

class dirinfo {
public static void main(String s[]){
deldir(s[0]);
}

public static void deldir(String st){
File f= new File(st);
if (f.isFile())
{
try{
Runtime.getRuntime().exec("del " + f.getAbsolutePath() );
return;
} catch(IOException e) {System.out.println("EXCEPTION: " + e);}
}

String[] fl= f.list();
for (int i=0;i<fl.length;i++)
deldir(fl);
}
}

It compiles without error. On giving a command like,
java dirinfo c:\test or c:\\test,
my test directory in c: doesnt have dirinfo.java/class file.
i get the following error:-

EXCEPTION : java.io.IOException CreateProcess del
d:\html\fileinfo.java error=0
Exception in thread "main"
java.lang.NullPointerException
at dirinfo.deldir(dirinfo.java:19)
at dirinfo.deldir(dirinfo.java:20)
at dirinfo.main(dirinfo.java:5)

Can anyone help???

thanx,
john.

Comments

S VISHAL KUMAR

Is the space in the folder name mandatory ? Please change the folder name to single word or use _ in between and try again.

Thanks,

Vishal Kumar

S VISHAL KUMAR

Hello,

It seems, OATS requires that the installation directory does not contain any special characters and may be because of space it is not working as expected.

Thanks,

Vishal Kumar

1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 29 2001
Added on Jul 26 2001
6 comments
134 views