use*_*231 5 java linux apache jsp
我可以获得可用磁盘空间.我如何获得总磁盘空间?
我的代码是:
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
FileSystemUtils没有磁盘总空间的方法??? 希望你的回复
提前致谢
如果您使用的是Java6,则File类将执行以下操作:
public long getTotalSpace()
public long getFreeSpace()
public long getUsableSpace()
Run Code Online (Sandbox Code Playgroud)
尝试
System.out.println(new File("/").getTotalSpace()/1024/1024/1024); //in GB
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8198 次 |
| 最近记录: |