java获取磁盘空间大小

来源:互联网 发布:网络交易管理办法 pdf 编辑:程序博客网 时间:2024/05/10 08:34
public class SpaceCheck {  
    public static void main(String[] args) {  
        File[] roots = File.listRoots();  
        for (File _file : roots) {  
            System.out.println(_file.getPath());  
            //System.out.println(_file.getName());  
            System.out.println("Free space = " + (_file.getFreeSpace()/(1024*1024))/1024+"G");  //显示GB大小
            System.out.println("Usable space = " + _file.getUsableSpace());  
            System.out.println("Total space = " + _file.getTotalSpace());  
            System.out.println("used space  = " + (_file.getTotalSpace()-_file.getFreeSpace()));  
            System.out.println();  
        }  
        File win = new File("C:\\WINDOWS");  
        System.out.println(win.getPath());  
        System.out.println(win.getName());  
        System.out.println("Free space = " + win.getFreeSpace());  
        System.out.println("Usable space = " + win.getUsableSpace());  
        System.out.println("Total space = " + win.getTotalSpace());  
        System.out.println();  
    }  
}

0 0
原创粉丝点击