I'm new to Java, just trying to make a simple utility to move, copy & delete some wav files on my pc, but java.io.File delete() fails. The wav files in question have read-only unchecked (in windows explorer) but File canWrite() returns false & setWritable(true) fails. I must be doing something stupid because nobody seems to have had this problem before?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You are using a relative path and you are not in the directory you think you are.
Specify absolute paths or determine the current path before starting.
回答2:
Run the java application as administrator. Then try.
file.setWritable(true);
file.delete();
回答3:
Try to run the garbage collector:
File file = new File("test-file.txt");
System.gc()
boolean success = file.delete();
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/System.html