This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Getting the free disk space

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone known a pure java solution (or alternative methods) for this problem?? (Don�t tell me about JConfig)
 
Bartender
Posts: 9586
13
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no functionality in the API to get the free disk space. The work-around I've seen involves exec()ing the appropriate platform-dependent command (dir on Windows, df on *nix) and parsing out the answer.
 
Proteu Alcebidiano
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dir command is problematic...
if I list a directory from a empty disk (a:\ for example) the output cannot return the free disk space

Its necessary to have some file inside the disk...



Do you know any alternative method for this problem?

thanx
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Proteu,

I have an alternative. You may not like it, but it's better than nothing. I managed to solve the problem of disc space reporting by downloading the excellent and free Cygwin, and calling the "df" command with exec().

You don't need to have the entire Cygwin distribution installed on the machine executing the code when you use df: I only use df.exe and the two DLLs required by df.exe (cygiconv-2.dll and cygwin2.dll), in a special lib directory I created for the assorted binary utilities used by my code.

As I'm creating a custom Ant task in Java that will check the available disc space before a build runs, this method seemed to be the best way of doing it, when considering my available time, my limited programming skill, and my requirements. And of course it would be easy to convert my Ant script to run on a Linux or Unix, because df is a standard tool.

There's a snippet of my code at the end of my code... it's a bit rubbishy, but I'm not a developer, and all I wanted was to get it working. You will be able to at least get an idea of what I'm doing.

This is the output it produces when called from ant:


This is the Ant code I use to call the Java:

This is the source code from CheckDiscSpace.java:


Hope you find it at least somewhat useful. If not, you haven't lost anything.


Bertie

[ November 17, 2004: Message edited by: Bertie Ramsbottom ]
[ November 17, 2004: Message edited by: Bertie Ramsbottom ]
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!