File.delete returns false.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    File.delete returns false.

    Code:
    File l_file = new File(path);
    System.out.println(l_file.exists()); //returns true
    System.out.println(l_file.delete()); //returns false
    How does this happen? Could anyone explain?
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Do you have permissions to delete the file? Someone else may have the file open.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Then i think program would have an security exception or IO exception.Is not it?

      Comment

      • Dheeraj Joshi
        Recognized Expert Top Contributor
        • Jul 2009
        • 1129

        #4
        Is this file being used by somebody else or some other processes?

        Regards
        Dheeraj Joshi

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Ok. tell me one thing when File.deleted throws Exception and when returns false?

          Comment

          • jkmyoung
            Recognized Expert Top Contributor
            • Mar 2006
            • 2057

            #6
            It could also be that the path you are pointing to is a non-empty directory.

            I 'think' you only get a SecurityExcepti on if you don't have permissions to delete the file, but just false for most other situations.

            Comment

            Working...