In my jUnit, i have a following snippet:
private String session = "/tmp/session/";
private File f;
@Before
public void setUp() {
f = new File(session);
f.mkdir();
}
@After
public void tearDown() {
System.out.println("Directory deleted: " + f.delete()); // always false
}
Meanwhile:
- Directory permissions are ok (
drwxr-xr-x) - Directory contains some files (
-rw-r--r--) - No ownership issues (Creator user deletes)
What would cause for f.delete() to fail? Is f.delete() an equivalent of rm -rf ?
From the API documentation for File.delete:
Note the bit about the directory needing to be empty.