Java file deletion fails -


i need delete files within java program , have written code. fails delete file , can't figure why. file not in use , not write protected.

public static void delfile(string filetodel) {     try {         file file = new file("filetodel");          if (file.delete()) {             system.out.println(file.getname() + " deleted!");         } else {             system.out.println("delete operation failed." + filetodel);         }     } catch (exception e) {         e.printstacktrace();     } } 

if want delete file, there no need loading it.

java.nio.file.files.deleteifexists(filetodel); (where filetodel contains path file)

returns true if file deleted, can put in if-clause.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -