Harold: Getting Available Free Disk Space

Hello,

is there any API-conform and platform-independend way
for getting the free disk space of a harddrive?

All code-snippets I found were just bad workarounds.

So, do anyone know a good way for doing this?

regards
Harold

  1. Hi Harold,

    is there any API-conform and platform-independend way
    for getting the free disk space of a harddrive?

    All code-snippets I found were just bad workarounds.

    So, do anyone know a good way for doing this?

    I searched for 15 minutes now, and I only found those bad workarounds that you found too.
    I think the best method would be to use the binarys of the different operating systems, on linux it would be "du" (standing for disk usage).

    This is quite a bit problematic because this function _really_ depends on the specific os, and (of course) the used file system. :-(

    Regards

    Marc Reichelt || http://www.marcreichelt.de/

    --
    Linux is like a wigwam - no windows, no gates and an Apache inside!
    Selfcode: ie:{ fl:| br:> va:} ls:< fo:} rl:( n4:( ss:) de:> js:| ch:? sh:| mo:) zu:)
    http://emmanuel.dammerer.at/selfcode.html
    1. Hi,

      I'm really filled with indignation. that was not that
      kind of answer I acpected to retrieve ;-(
      but thanks a lot anyway..

      Its really amazing that the developers did not implement
      those functionality so far.. in the meantime there's Java
      1.5 out now. It's unbelievable..

      In my honest opinion this really sucks.. I mean: where the
      hell is the platform-independency in Java they touted so
      loud every time?

      Regards
      frustrated Harold

      1. Hi there,

        In my honest opinion this really sucks.. I mean: where the
        hell is the platform-independency in Java they touted so
        loud every time?

        It's not a bug, it's a feature ;) think of devices, that even don't have a harddisk, like cellularphones, where "free disk space" has a complete different meaning...

      2. Hej,

        In my honest opinion this really sucks.. I mean: where the
        hell is the platform-independency in Java they touted so
        loud every time?

        You have to look at it the other way around: Because they want it to be a platform-independent the developers turned such options down. Consider a coffee machine having a Java-VM running on it, what would a method getFreeDiskSpace() be good for?

        Java was from the very first not intended to target any platform. For this intention other languages like C or C++ exist. You should consider anyways, if Java is the right choice for your project, if you need such functionality.

        However, as we found out allready, Java is still not at the end of the developing process and with the Mustang-release such functions will be provided. Till then you will have to use workarounds.

        Best
        Biesterfeld

        --
        "Nein! ... Nein, schneller, leichter, verführerischer die dunkle Seite ist."
        1. Hallo.

          You have to look at it the other way around: Because they want it to be a platform-independent the developers turned such options down. Consider a coffee machine having a Java-VM running on it, what would a method getFreeDiskSpace() be good for?

          Seltsames Argument, oder hast du schon einmal mit einer Kaffemaschine gedruckt? -- Nein, gedruckt; nicht gekleckert.
          MfG, at

          1. Hej,

            You have to look at it the other way around: Because they want it to be a platform-independent the developers turned such options down. Consider a coffee machine having a Java-VM running on it, what would a method getFreeDiskSpace() be good for?

            Seltsames Argument, oder hast du schon einmal mit einer Kaffemaschine gedruckt? -- Nein, gedruckt; nicht gekleckert.

            Ähm nö. *Isch 'ahbe gar keine Kaffeemaschine!*

            Wahrscheinlich spielst du auf die Java Print Service API an. Natürlich hat Java inzwischen sehr viele Funktionen in die java.*- und javax.*-Bibliotheken aufgenommen die hardwarenah sind.

            Ich sehe auch durchaus den Spagat den die Entwickler vollziehen müssen, nämlich zwischen absoluter Plattformunabhängigkeit (die sowieso nie gewährleistet werden konnte) und Funktionalität.

            Ich versuche lediglich zu erklären warum es _bisher_ die vom OP erfragte Funktionalität noch nicht gibt. Ebenso wie es die JPS nicht seit der ersten Version gab.

            Aber wäre doch mal lustig, sich von seinem Kaffeeautomaten ein Ergebnisprotokoll drucken zu lassen ;)

            Beste Grüße
            Biesterfeld

            --
            "Nein! ... Nein, schneller, leichter, verführerischer die dunkle Seite ist."
            1. Hallo.

              Aber wäre doch mal lustig, sich von seinem Kaffeeautomaten ein Ergebnisprotokoll drucken zu lassen ;)

              Meine macht das, aber das Schriftbild der sepia-farbenen Pigmente auf dem sehr saugfähigen Papier lässt doch ein wenig zu wünschen übrig.
              MfG, at

    2. I think the best method would be to use the binarys of the different operating systems, on linux it would be "du" (standing for disk usage).

      df. Nicht du.

      1. Hi Anonymous,

        I think the best method would be to use the binarys of the different operating systems, on linux it would be "du" (standing for disk usage).

        df. Nicht du.

        Yes of course ;-)
        "Disk free"...

        Regards

        Marc Reichelt || http://www.marcreichelt.de/

        --
        Linux is like a wigwam - no windows, no gates and an Apache inside!
        Selfcode: ie:{ fl:| br:> va:} ls:< fo:} rl:( n4:( ss:) de:> js:| ch:? sh:| mo:) zu:)
        http://emmanuel.dammerer.at/selfcode.html
  2. Hej,

    is there any API-conform and platform-independend way
    for getting the free disk space of a harddrive?

    AFAIK not yet. Sure, you have the possibility to write your own native classes. Also you can try workarounds using Runtime.exec(). But neither Java SE 1.4.2 nor the Tiger provide options for your intention.

    You'll have to wait for the Mustang-Release (aka Java SE 6.0), which will come up with Methods like File.getFreeSpace() or File.getTotalSpace().

    Best
    Biesterfeld

    --
    "Nein! ... Nein, schneller, leichter, verführerischer die dunkle Seite ist."