Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOException for drive full or out of space

I am looking for a list of platform-specific (JRE-specific) of IOException messages indicating disk is full or out of space.

So far I have:

  • Windows: There is not enough space on the disk
  • Solaris/Linux?: Not enough space
  • GCJ: No space left on device

I wish Java would make an IOException subclass for this...

like image 274
Ben Avatar asked Jun 08 '09 18:06

Ben


2 Answers

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!)

like image 59
Matt Avatar answered Oct 21 '22 00:10

Matt


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.

like image 39
Kathy Van Stone Avatar answered Oct 20 '22 23:10

Kathy Van Stone