Java 7是否有办法将文件放入回收站,而不是在Windows上删除 [英] Does Java 7 have a way to put files in recycle bin rather than delete on Windows

查看:184
本文介绍了Java 7是否有办法将文件放入回收站,而不是在Windows上删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 7是否有办法将文件放入回收站,而不是在Windows上删除? 我知道它在Java 6中不存在,但是我真的以为这已经添加到Java 7中了,但是一直找不到,如果没有第三方库可以做到这一点,我不想摆弄和我自己的JNI.

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.

首先,您可以使用Apple扩展程序在OSX上完成此操作

FWIW you can do this on OSX using the Apple extension

com.apple.eawt.FileManager.moveToTrash()

使用了jna库作为答案. FWIW在maven中央存储库中可用,但是您需要同时包含jna pom和platform pom,因为platform jar是包含回收站方法的容器.

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>

推荐答案

我认为答案是否定的.

存在第三方库,JNA支持此库(请参阅

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.

此RFE倾向于确认这一点: http://bugs.sun.com/view_bug.do?bug_id=5080625

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

这篇关于Java 7是否有办法将文件放入回收站,而不是在Windows上删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆