How to recursively clear directories in Java

Asked 2 years ago, Updated 2 years ago, 108 views

Is there a way to recursively erase the entire directory in Java? Usually, it's possible to erase empty directories. But if there's a file in the directory that you erase, it gets a little hard. How do I erase the directory where the file is located?

java file-io filesystems delete-directory

2022-09-21 20:27

1 Answers

If you look at the Apache Common library, there is a class called FileUtils. If you use this, you can do it. FileUtils.deleteDirectory(new File("directory")); You can do it in this way.


2022-09-21 20:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.