Does Java 7 have a way to put files in recycle bin rather than delete on Windows

半腔热情 提交于 2019-12-08 16:33:13

问题


Does Java 7 have a way to put files in recycle bin rather than delete on WIndows ? I know it doesn't exist in Java 6, but I really thought this was getting added to Java 7 but have been unable to find it, if not is there a 3rd party library available to do this, I don't want to fiddle with JNI myself.

FWIW you can do this on OSX using the Apple extension

com.apple.eawt.FileManager.moveToTrash()

EDIT: Used the jna library as in answer. FWIW it is available on maven central repository, but you need to include both the jna pom and the platform pom, as the platform jar is the one that contains the recycle bin method.

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>3.4.0</version>
</dependency>

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>platform</artifactId>
    <version>3.4.0</version>
</dependency>

回答1:


I think that the answer is No.

3rd party libraries exist, and this is supported in JNA (see Java on Windows: how to delete a file to trash (using JNA)), but this functionality is not part of the standard Java 7 platform, AFAIK.

This RFE tends to confirm this: http://bugs.sun.com/view_bug.do?bug_id=5080625



来源:https://stackoverflow.com/questions/12143952/does-java-7-have-a-way-to-put-files-in-recycle-bin-rather-than-delete-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!