Languages
[Edit]
EN

Java - delete directory

0 points
Created by:
Emerson-V
333

In this article, we would like to show you how to delete a directory in Java.

Below we describe several ways on how to delete a directory:

  • Recursively,
  • Files.walkFileTree (Java 7)

 

Project structure

Edit

1. Recursively

Edit

In this example, we use recursion to delete a non-empty directory, because to delete the directory we need to clear it first.

Output:

2. Files.walkFileTree

Edit

In this example, we use Files.walkFileTree with SimpleFileVisitor to delete a directory.

Output:

Alternative titles

  1. Java - delete folder
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - file operations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join