0
i want delete a file in java
i want to delete a file using the delete() method but it doesn't work. I create the file in another class. my code: username = scanner.nextLine(); File file = new File(username + ".txt"); if(file.exists()){ file.delete(); if (file.delete()){ System.out.println("your account deleted."); }else System.out.println("no"); }else System.out.println("username is wrong");
2 Réponses
+ 9
Use this method
Files.deleteIfExists(Paths.get(filepath));
+ 4
@A͢J
Thank you!!!