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)?
Maverick Lasa
Greenhorn
Joined: Oct 18, 2003
Posts: 23
posted
0
I don't know if there is already an available API for this one but you can do this thru JNI. Calling the native library such as GetDiskFreeSpace/Ex in Windows. mavedrive;
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?
Many thanks for your responses. I was hoping I could do this without using Runtime.exec(). (It must run on Windows and AIX). Oh, well, I guess I just detect which I am on and write both.... Don
Brian Pipa
Ranch Hand
Joined: Sep 29, 2003
Posts: 299
posted
0
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