Results 1 to 7 of 7
  1. #1
    vaibhavspawar is offline Member
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default About File handle...

    Hello Friends...
    I am trying to delete a file using some code. But it's not getting deleted
    with delete() function of 'File' class. I had been told that it might be
    getting used by some other program. So Please tell me is there anyway
    we can check whether the file is being used by some other program or not?
    Thanks. Bye... :)

  2. #2
    ajaysingh87 is offline Member
    Join Date
    Jul 2010
    Location
    India, Mumbai
    Posts
    5
    Rep Power
    0

    Default

    will you plz send me code snippet,
    why don't u try something like this.
    File file = new File("c:\\abc.txt");
    if(file. exists())
    {
    file.delete();
    }

    ......(SINGH IS KING):)

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Because that is nonsense.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    vaibhavspawar is offline Member
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by ajaysingh87 View Post
    will you plz send me code snippet,
    why don't u try something like this.
    File file = new File("c:\\abc.txt");
    if(file. exists())
    {
    file.delete();
    }

    ......(SINGH IS KING):)


    Thanks Ajay, but I,ve already mentioned that delete() function isn't deleting the file. I want the way to know that whether the file I am trying to delete is being used by some other program.
    Thanks. Bye :)

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Presumably if delete() returns false then you can assume that either the user doesn't have permission to delete the file, or the file is in use. So check that flag and inform the user if it comes back false..."Cannot delete file blah. Either it is in use or you do not have sufficient privileges."
    Something like that.

  6. #6
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Do you have FileOutput/InputStreams open to the file you try to delete? That could be causing your problem as well... make sure you call the close() method on any FileXXXStream you use.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  7. #7
    vaibhavspawar is offline Member
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by Singing Boyo View Post
    Do you have FileOutput/InputStreams open to the file you try to delete? That could be causing your problem as well... make sure you call the close() method on any FileXXXStream you use.


    Hello...
    Thanks for suggestion.... :)
    I've already closed all the streams & buffers. So I think the handle isn't getting released unless Application is closed.
    :)

Similar Threads

  1. Handle sound
    By varsamakos in forum AWT / Swing
    Replies: 4
    Last Post: 12-26-2009, 09:40 PM
  2. how to handle files?
    By sayan751 in forum Advanced Java
    Replies: 5
    Last Post: 06-10-2009, 08:39 PM
  3. handle FileNotFoundException
    By minifish in forum New To Java
    Replies: 13
    Last Post: 11-08-2008, 02:01 AM
  4. [SOLVED] reader and writer on same file handle
    By Nicholas Jordan in forum Advanced Java
    Replies: 11
    Last Post: 07-01-2008, 03:39 AM
  5. Better way to handle exceptions
    By javaplus in forum Advanced Java
    Replies: 2
    Last Post: 01-16-2008, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •