I have a java process that writes out a file. Before I write the file I want to detect how much space there is left. In Java, how do I detect how much space is left on a drive (without filling that space)?
On windows you could do a Runtime.exec() on dir, read the output from the Process's output stream and parse out the last number, which is the free disk space. Linux (and maybe Unix in general) has a specific command, df, for free space. How's that for a kludge?
There are no built-in Java APIs to do this. You could write some jNI code to make native calls, but that's a hassle and you'd have to write native code for every platform you wanted to support. if you're only supporting 2 OSes, it might be easier to just write a class that does the execing for you. brian