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

java.awt.Desktop.moveToTrash(java.io.File):

public boolean moveToTrash​(File file)

Moves the specified file to the trash.

Parameters:

file – the file

Returns:

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