How to find how much disk space is left using Java?

Roman Kagan picture Roman Kagan · Jun 26, 2009 · Viewed 85.9k times · Source

How to find how much disk space is left using Java?

Answer

Kredns picture Kredns · Jun 26, 2009

Have a look at the File class documentation. This is one of the new features in 1.6.

These new methods also include:

  • public long getTotalSpace()
  • public long getFreeSpace()
  • public long getUsableSpace()

If you're still using 1.5 then you can use the Apache Commons IO library and its FileSystem class