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

前端 未结 9 1825
夕颜
夕颜 2020-12-13 18:12

Java is the key here. I need to be able to delete files but users expect to be able to \"undelete\" from the recycle bin. As far as I can tell this isn\'t

相关标签:
9条回答
  • 2020-12-13 19:00

    See the fileutil incubator project (part of the Java Desktop Integration Components project):

    This incubator project is created to host those file utility functionalities, most of which are extensions to the java.io.File class in J2SE. There are frequent requests from Java developers for such features like: sending a file to trash bin, checking free disk space, accessing file attributes etc. This project addresses such frequently requested APIs.

    Note, this should work not only on Windows, but on other platforms (Linux, Mac OS X) as well.

    0 讨论(0)
  • 2020-12-13 19:06

    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).

    0 讨论(0)
  • 2020-12-13 19:09

    Here's the correct link to the example for using SHFileOperation to send a file to the recycle bin.

    0 讨论(0)
提交回复
热议问题