Java is the key here. I need to be able to delete files but users expect to be able to "undelete" from the recycle bin. As far as I can tell this isn't possible. Anyone know otherwise?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Java 9 has new method but in my case I am restricted to Java 8. I found Java Native Access Platform that has hasTrash() and moveToTrash() method. I tested it on Win 10 and Mac OS (Worked) for me.
Maven Repository https://mvnrepository.com/artifact/net.java.dev.jna/jna-platform/5.1.0
Don't confuse It is Java Native Access Platform not Java Native Access
I have found this RFE on suns site: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5080625
This tells me there is not a native java way to do this. and as @John Topley just posted the only solution is a JNI call.
My 3 cents - use cmd util Recycle.exe with -f to force recycle (no prompt). Works perfectly.
See the fileutil incubator project (part of the Java Desktop Integration Components project):
Note, this should work not only on Windows, but on other platforms (Linux, Mac OS X) as well.
For various reasons Windows has no concept of a folder that simply corresponds to the Recycle Bin.
The correct way is to use JNI to invoke the Windows
SHFileOperation
API, setting theFO_DELETE
flag in theSHFILEOPSTRUCT
structure.As John Topley suggests, you must do this with a native operation. In case you don't want to get your hands dirty with some JNI, you could use a library called Java Native Access to do the native calls.