File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Available space for file on server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Available space for file on server" Watch "Available space for file on server" New topic

Available space for file on server

Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464

A server accepts files from a client. The files could be any size. The client can communicate the file's size to the server before starting the transfer which is fine. What I am trying to achieve is to be able to respond to the client whether or not there is enough space on the server to store that file before the transfer begins.

The issue of course is that Java has no way to ascertain the free space on a given filesystem. I cannot go native because the application must be platform independant so I need to find a Java only solution.

Does anyone have any ideas?

My first thought is to write out a temp file of the size of the client file and then if that doesnt error, accept the transfer but this seems like a very poor solution to what should be a simple problem...

Thanks in advance.

ph34r my 133t j4v4 h4><0r1ng sk177z
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
I found this via google:

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Thank you - I should have googled. I will wait until 6 then.

J Wenting has commented in there - I wonder if it is the same one that comes here.
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Ooooh - I missed the last comment - apparently Apache Commons can do this. Thanks Ilja
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Note that JDK 6 Beta is available now, and the methods you want are in the File class: getFreeSpace() and getUsableSpace().

"I'm not back." - Bill Harding, Twister
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
But no matter how you get the free space, if at some instant ten thread all see a meg free, they can't all write a meg file. Clients should still be prepared for disappointment now and then.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Available space for file on server
It's not a secret anymore!