Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deleting a file in java

 
Tim frank
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kanu Dialani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic