8

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>
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351

1 Answers1

2

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

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • That link doesn't make much sense, does that sun class always exist on Windows or it got be created. – Paul Taylor Aug 27 '12 at 14:39
  • 1
    @PaulTaylor - that link/functionality is part of the [JNA](https://github.com/twall/jna) project. – jtahlborn Aug 27 '12 at 15:07
  • Ah thanks, I didn't realize this was what JNA was I thought it was just a newer version of JNI, I'll give this a go here is a updated link a sit has moved to GitHub https://github.com/twall/jna/blob/master/www/GettingStarted.md – Paul Taylor Aug 27 '12 at 15:17