如何绕过 java.nio.file.DirectoryNotEmptyException?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29872608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to bypass java.nio.file.DirectoryNotEmptyException?
提问by Lucas Baizer
Is there a way to bypass a java.nio.file.DirectoryNotEmptyException? I want to be able to delete a folder with content in it.
有没有办法绕过 java.nio.file.DirectoryNotEmptyException?我希望能够删除包含内容的文件夹。
采纳答案by Stephen C
Is there a way to bypass a
java.nio.file.DirectoryNotEmptyException
?
有没有办法绕过a
java.nio.file.DirectoryNotEmptyException
?
No. There is no way to bypass it.
不,没有办法绕过它。
On Linux / Unix, the restriction is ultimately imposed by the operating system. See man 2 rmdir
, and the ENOTEMPTY
error code.
在 Linux / Unix 上,限制最终是由操作系统强加的。请参阅man 2 rmdir
和ENOTEMPTY
错误代码。
Also, try running rmdir
from the command prompt on a non-empty directory, and see what happens.
另外,尝试rmdir
在非空目录上从命令提示符运行,看看会发生什么。
As other comments state, you need to empty the directory first.
正如其他评论所述,您需要先清空目录。
回答by dave
No, you cannot bypass it. You will need to delete the files and sub-directories first. There are many examples on the web of how to do this.
不,你不能绕过它。您需要先删除文件和子目录。网上有很多关于如何执行此操作的示例。