Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 487
Paul Taylor Avatar asked Aug 27 '12 14:08

Paul Taylor


1 Answers

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

like image 153
Stephen C Avatar answered Oct 14 '22 03:10

Stephen C