File.delete() does not work for directories on solaris
see code example below. Works for files, but not for directories.
import java.io.*;
// makes use of the File class
class deletefile {
public static void main(String args[]) {
boolean filedeleted = true;
File Filo = new File(args[0]);
System.out.println ("Path sep " + Filo.pathSeparator );
filedeleted = Filo.delete ();
System.out.println ( "filedeleted = " + filedeleted );
}
}
$ java deletefile testfile
Path sep :
filedeleted = true
/home/kammy/testprogs/jh (kokomo)
$ ls testfile
testfile: No such file or directory
/home/kammy/testprogs/jh (kokomo)
$ java deletefile testdir2
Path sep :
filedeleted = false
/home/kammy/testprogs/jh (kokomo)
$ ls
deletefile.class fileOps.java testdir/
deletefile.java fileOpsMain.java testdir2/
see code example below. Works for files, but not for directories.
import java.io.*;
// makes use of the File class
class deletefile {
public static void main(String args[]) {
boolean filedeleted = true;
File Filo = new File(args[0]);
System.out.println ("Path sep " + Filo.pathSeparator );
filedeleted = Filo.delete ();
System.out.println ( "filedeleted = " + filedeleted );
}
}
$ java deletefile testfile
Path sep :
filedeleted = true
/home/kammy/testprogs/jh (kokomo)
$ ls testfile
testfile: No such file or directory
/home/kammy/testprogs/jh (kokomo)
$ java deletefile testdir2
Path sep :
filedeleted = false
/home/kammy/testprogs/jh (kokomo)
$ ls
deletefile.class fileOps.java testdir/
deletefile.java fileOpsMain.java testdir2/
- duplicates
-
JDK-1231492 FIle.delete() will not remove directories
-
- Closed
-