File System full scenario
How do I know if file system is full ? Is there an exception that I can catch ?
How do I know if file system is full ? Is there an exception that I can catch ?
When you try to write, you'll get an IOException. I don't think there's a specific subclass for disk full though.
The new (Java 1.6) java.io.File class provides a getFreeSpace() method.
Note that this does not check the (physical) disk, but rather the partition of it.
http://java.sun.com/javase/6/docs/api/java/io/File.html
Are you planning on handling a 'file system full' exception any differently than you would any other kind of IOException? Hopefully not, or that's probably not a good idea.
Oh, cool. Didn't know that.
@OP: Note, however, that even if there's enough free space, by the time you try to write, there might not be, and if there's not, by the time you try to write, it might open up.
We are using 1.5. I need to know if file system is full so that I can raise critical alert for others to see
> We are using 1.5. I need to know if file system is
> full so that I can raise critical alert for others to
> see
Define "full".
There's no way to do it in 1.5 except to try to create a file as big as what would have to be left for it to be not "full" (e.g. with RandomAccessFile), see if it works, and then alert if it doesn't. Or Runtime.exec "df" for unix or whatever the Win equivalent is. Or use JNI.
Or you could look into an SNMP-based solution, but that may be overkill if file-system full is all you want.