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

Ten years later, with Java 9, finally there is a builtin way to move files to the Trash Bin


public boolean moveToTrash​(File file)

Moves the specified file to the trash.


file – the file


returns true if successfully moved the file to the trash.

The availability of this feature for the underlying platform can be tested with Desktop.isSupported​(Desktop.Action.MOVE_TO_TRASH).

Leave a Comment