File System full scenario

How do I know if file system is full ? Is there an exception that I can catch ?

[86 byte] By [mohitanchliaa] at [2007-11-27 11:26:25]
# 1

When you try to write, you'll get an IOException. I don't think there's a specific subclass for disk full though.

jverda at 2007-7-29 16:10:19 > top of Java-index,Java Essentials,Java Programming...
# 2

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

prometheuzza at 2007-7-29 16:10:19 > top of Java-index,Java Essentials,Java Programming...
# 3

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.

warnerjaa at 2007-7-29 16:10:19 > top of Java-index,Java Essentials,Java Programming...
# 4

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.

jverda at 2007-7-29 16:10:19 > top of Java-index,Java Essentials,Java Programming...
# 5

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

mohitanchliaa at 2007-7-29 16:10:19 > top of Java-index,Java Essentials,Java Programming...
# 6

> 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.

jverda at 2007-7-29 16:10:19 > top of Java-index,Java Essentials,Java Programming...