当File.listFiles返回null时检索基础错误 [英] Retrieving the underlying error when File.listFiles return null

查看:135
本文介绍了当File.listFiles返回null时检索基础错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 File.listFiles javadoc 该方法


如果此抽象路径名不表示一个目录,或者I / O错误发生。


我知道我正在使用一个目录,但收到了一个 null 结果,所以必须出现I / O错误。我非常感兴趣的是什么错误。

当这样的 null result is returned?

解决方案使用 java.nio.file.DirectoryStream (在Java 7+中),你将得到适当的例外。


According to the File.listFiles javadoc the method

Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

I know that I am using a directory, but have received a null result, so an I/O error must've appeared. I'm very much interested in what the error was.

How can I retrieve the error message/code when such a null result is returned?

解决方案

Use java.nio.file.DirectoryStream (in Java 7+) and you will get proper exceptions.

这篇关于当File.listFiles返回null时检索基础错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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