1

I can't find anywhere that explains this, but I might have just missed it. Anyway, if you use java.io.File.delete () to delete a file, what happens to the file? I only need an answer for how this works on Windows. Does the file get sent to the Recycling Bin, a separate designated location for files that were deleted by Java, or is it completely lost? Again, sorry if this is a duplicate. I couldn't find an answer anywhere. Thanks

user6615347
  • 101
  • 1
  • 7
  • It is completely gone I believe. – Andrew Li Oct 25 '16 at 21:02
  • I may be wrong in general FS or NTFS terms, but such a file is marked as deleted from the FS, but not moved to any special location e.g. the Recycle Bin. It's not lost per se, physically it's still in the FS and there are even some possibility to restore the file as long as it's not overwritten in the FS metadata or blob storage areas while allocating new files or moving the old ones. Restoring a deleted file in NTFS is not a trivial task and there are a few tools to make this kind of "surgery". Deleting a file to the Recycle Bin is a sort of file move along with some metadata – Lyubomyr Shaydariv Oct 25 '16 at 21:21

1 Answers1

1

Using the Recycle Bin is a bit more complicated to do than using File.delete(). To make Java work on every platform, File.delete() simply deletes the file for good.

Is it possible with Java to delete to the Recycle Bin?

If you want to not actually delete the files completely, why not move "deleted" files to your app's own designated folder and clear the folder periodically?

Community
  • 1
  • 1
Michael Fulton
  • 4,608
  • 3
  • 25
  • 41