How to find how much disk space is left using Java?
How to find how much disk space is left using Java?
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
Use CommonsIO and FilesystemUtils:
e.g.
FileSystemUtils.freeSpaceKb("/");
or built into the JDK:
http://java.sun.com/javase/6/docs/api/java/io/File.html#getFreeSpace()
new File("/").getFreeSpace();