IOException for drive full or out of space

做~自己de王妃 提交于 2019-12-03 02:39:19
Matt

The wording is actually a system message, not one from the JRE. (POSIX compliant will return "Not enough space")

As such, your best bet is to get a list of system error messages for the OS' you are targeting.

Alternatively, when the exception is thrown, you could check to see if there is any space remaining on the disk.

From the apache commons IO:

FileSystemUtils.freeSpaceKb(String path);

will return free space on the drive/volume (or maybe even throw an IOException!)

As to why there is not a IOException subclass, I suspect that the operating system file call does not give enough information in enough cases for Java to know what the error is without parsing the error message (a very fragile operation at best). This is probably true of a number of io calls.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!