Two Laptop Bag*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Deleting a file in java" Watch "Deleting a file in java" New topic

Deleting a file in java

Tim frank

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

Joined: Jul 08, 2003
Posts: 24183

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

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

Joined: Jul 08, 2003
Posts: 24183

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!
I agree. Here's the link:
subject: Deleting a file in java
Similar Threads
Program for Virus Checking
[Humor] New Computer Viruses
using javac to compile a cvs controlled project
Only fun forwards for fun ...
not loading the jasper xml files