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

1

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>
Ashia answered 27/8, 2012 at 14:26 Comment(5)
Possibly an answer: https://mcmap.net/q/1473353/-using-java-39-s-file-delete-methodGreer
And another one: #3709992Wehrle
Was hoping something had changedAshia
For what it's worth, I'm very happy this all but useless feature is not supported.Spearhead
You think a recycle bin is useless, why you'll never delete anthing my mistake and nor will your users.Ashia
F
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: https://bugs.java.com/bugdatabase/view_bug?bug_id=5080625

Forestforestage answered 27/8, 2012 at 14:33 Comment(3)
That link doesn't make much sense, does that sun class always exist on Windows or it got be created.Ashia
@PaulTaylor - that link/functionality is part of the JNA project.Oringas
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 github.com/twall/jna/blob/master/www/GettingStarted.mdAshia

© 2022 - 2024 — McMap. All rights reserved.