如何使用Java查找剩余的磁盘空间?

问题描述:

如何使用Java查找剩余的磁盘空间?

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

查看文件类 文档.这是 1.6 的新特性之一.

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

这些新方法还包括:

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

如果您仍在使用 1.5,那么您可以使用 Apache Commons IO 库及其文件系统类

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