• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Available space for file on server

 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this via google: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4057701
 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooooh - I missed the last comment - apparently Apache Commons can do this. Thanks Ilja
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that JDK 6 Beta is available now, and the methods you want are in the File class: getFreeSpace() and getUsableSpace().
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic