This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Deleting a file in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Deleting a file in java" Watch "Deleting a file in java" New topic
Author

Deleting a file in java

Tim frank
Greenhorn

Joined: Mar 07, 2006
Posts: 25
Hey guys, im currently working on a virus scanner, its all working perfectly except for it wont delete the binary files for some reason. I have:



It doesn't work tho, the boolean value returned is always false.

Does anyone know why its not working?
Much appricaited.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The most obvious explanation is that there's no such file; try checking the value of afile.exists().

Since you're on Windows, another important possibility is that the file is open for reading or writing; the OS won't let you delete an open file. Make sure it's closed.


[Jess in Action][AskingGoodQuestions]
Kanu Dialani
Greenhorn

Joined: Apr 30, 2005
Posts: 23
Also if u have any stream open which is using that file in ur java class it wont delete the file !
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

That's a good point -- which is why I made it.


Kanu, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Initials aren't enough. You can change your display name here. Thanks!
 
 
subject: Deleting a file in java