六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 37|回复: 0

java获取磁盘容量

[复制链接]

升级  18%

21

主题

21

主题

21

主题

秀才

Rank: 2

积分
77
 楼主| 发表于 2013-2-3 14:36:07 | 显示全部楼层 |阅读模式
package com.mkyong; import java.io.File; public class DiskSpaceDetail{    public static void main(String[] args)    {    File file = new File("c:");    long totalSpace = file.getTotalSpace(); //total disk space in bytes.    long usableSpace = file.getUsableSpace(); ///unallocated / free disk space in bytes.    long freeSpace = file.getFreeSpace(); //unallocated / free disk space in bytes.     System.out.println(" === Partition Detail ===");     System.out.println(" === bytes ===");    System.out.println("Total size : " + totalSpace + " bytes");    System.out.println("Space free : " + usableSpace + " bytes");    System.out.println("Space free : " + freeSpace + " bytes");     System.out.println(" === mega bytes ===");    System.out.println("Total size : " + totalSpace /1024 /1024 + " mb");    System.out.println("Space free : " + usableSpace /1024 /1024 + " mb");    System.out.println("Space free : " + freeSpace /1024 /1024 + " mb");    }}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表