• Post Reply Bookmark Topic Watch Topic
  • New Topic

not able to delete file

 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all. I am trying to do some operation on file. In which a file is written in other file leaving some line. Then that new file is renamed to older file. But that is not happening with ma code. can any one find where i went wrong. The code is below



Thanks and Regards
Adeeb
>
 
Greg Charles
Sheriff
Posts: 3010
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's certainly possible that the OS, security manager, or something else is preventing you from deleting the file. You should be looking at the boolean return values from the various calls you make. File.delete(), for example, returns false if the file can't be deleted, so your exception handler won't catch it. A couple of the calls, f.canRead() and f.canWrite(), don't do anything except return a boolean, so if you're not looking at the return value, there's no point to even making the call.

Take a look at the java.io.File API for more information.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If after taking Greg's advice you find that you do have permission to delete the file then it might be worth doing a System.gc() just prior to doing the delete(). I know I know I know - one never needs to invoke System.gc() and few believe that this can have an effect but what can it cost to try it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!