Java.nio: most concise recursive directory delete

前端 未结 6 874
日久生厌
日久生厌 2020-12-13 06:10

I am currently trying to recursively delete a directory... Strangely enough the shortest piece of code I was able to find is the following construct, employing an ad-hoc

6条回答
  •  北海茫月
    2020-12-13 06:58

    FileUtils.deleteDirectory from Apache Commons IO deletes a directory recursively.

    Example:

    Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME);
    
    boolean result = FileUtils.deleteDirectory(pathToBeDeleted.toFile());
    

    For more information see Delete a Directory Recursively in Java.

提交回复
热议问题