Move File to JAVA Recycle Bin

Asked

Viewed 72 times

1

Hello, there is some way I can move a File to the recycle bin instead of deleting it permanently?

 File f = new File("um caminho com um arquivo top aki);
 f.delete(); //retorna um true caso consiga deletar, e isso ocorre na hora.
 f.deleteOnExit();  //procedimento void que deleta o arquivo no fechamento da aplicação.
  • Looks like you have a new API in Java 9: https://docs.oracle.com/javase/9/docs/api/java/awt/Desktop.html#moveToTrash-java.io.File-

  • To do so would be java.awt.Desktop.moveToTrash(f) ?? because even with java 10 in my netbeans it is not working...

  • I’m trying to lower the Nb 11 to see if it resolves... already return with the result..

1 answer

1


As suggested by @Ezar the use of ToTrash() has worked.

To see the java version just go to cmd and check that it is java 9 or later

java -version

The Netbeans IDE used was 11.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.