maven 依赖:
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.0.0</version>
</dependency>
源代码:
package com.zhu.movetotrash;
import java.io.File;
import java.io.IOException;
import com.sun.jna.platform.FileUtils;
public class MoveToTrash {
/**
*
* @param filePath
* @return true on successful deletion of the file, filePath is null (or) empty.
* false in all other cases.
*/
public static boolean moveFileToTrash(String filePath) {
if (filePath == null || filePath.isEmpty()) {
System.out.println("filePath shouldn't be null (or) empty");
return true;
}
File file = new File(filePath);
if (!file.exists()) {
System.o