how to delete a directory
843798Jul 26 2001 — edited Aug 1 2001Hi 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.