在Java中递归地删除目录 [英] Delete directories recursively in Java

查看:118
本文介绍了在Java中递归地删除目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Java中递归地删除整个目录?



在正常情况下,可以删除一个空目录。
然而,当涉及到删除整个内容的目录,它不是那么简单了。

如何删除Java中的内容与整个目录?你应该看看 noreferrer> Apache的commons-io 。它有一个 FileUtils 类将会做你想做的。

  FileUtils.deleteDirectory(new File(目录)); 


Is there a way to delete entire directories recursively in Java?

In the normal case it is possible to delete an empty directory. However when it comes to deleting entire directories with contents, it is not that simple anymore.

How do you delete entire directories with contents in Java?

解决方案

You should check out Apache's commons-io. It has a FileUtils class that will do what you want.

FileUtils.deleteDirectory(new File("directory"));

这篇关于在Java中递归地删除目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆