我能够获得可用的磁盘空间。我如何获得总磁盘空间?
我的代码是:
import java.io.IOException; import org.apache.commons.io.FileSystemUtils; public class DiskSpace { public static void main(String[] args) { try { //calculate free disk space double freeDiskSpace = FileSystemUtils.freeSpaceKb(args[0]); System.out.println(args[0]); //convert the number into gigabyte double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024; System.out.println("Free Disk Space (GB):" + freeDiskSpaceGB); } catch (IOException e) { e.printStackTrace(); } } }
FileSystemUtils没有磁盘总空间的方法???希望您的答复
FileSystemUtils
提前致谢
尝试
System.out.println(new File("/").getTotalSpace()/1024/1024/1024); //in GB