• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

not able to delete file

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
>
 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic