Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Code unable to delete file

Tags:

java

My java code is unable to delete files on the the system hard drive.

Whenever file.delete() function is called, it returns false. Any ideas, why that might be happening?

like image 266
Vivek Avatar asked Jul 26 '10 10:07

Vivek


2 Answers

File.delete() can fail to delete a file for many reasons including:

  • you don't have correct permissions to delete the file
  • the file represents a directory and the directory is not empty
  • the file is locked by another process, (or even by the same process in say an unclosed FileOutputStream)
  • the file doesn't exist
like image 140
krock Avatar answered Oct 01 '22 20:10

krock


File.delete() can return false if you are trying to delete a directory that is not empty, or the named file simply doesn't exist at the time of the call.

(if there is a permission issue, a SecurityException is thrown)

like image 31
Greg Hewgill Avatar answered Oct 01 '22 22:10

Greg Hewgill