Delete a file or directory in a platform-specific manner. Removes a File object (a file or directory) from the system by placing it in the Trash or Recycle Bin (if available) or simply deleting it (if not). Also tries to find a suitable Trash location on Linux. When the file/folder is on another
(File file)
| 533 | * @throws IOException what went wrong |
| 534 | */ |
| 535 | static public boolean deleteFile(File file) throws IOException { |
| 536 | try { |
| 537 | FileUtils fu = FileUtils.getInstance(); |
| 538 | if (fu.hasTrash()) { |
| 539 | fu.moveToTrash(file); |
| 540 | return true; |
| 541 | } |
| 542 | } catch (Throwable t) { |
| 543 | // On macOS getting NoClassDefFoundError inside JNA on Big Sur. |
| 544 | // (Can't find com.sun.jna.platform.mac.MacFileUtils$FileManager) |
| 545 | // Just adding a catch-all here so that it does the fall-through below. |
| 546 | System.err.println(t.getMessage()); |
| 547 | } |
| 548 | |
| 549 | if (file.isDirectory()) { |
| 550 | Util.removeDir(file); |
| 551 | return true; |
| 552 | |
| 553 | } else { |
| 554 | return file.delete(); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | |
| 559 | // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
no test coverage detected