需要把磁盘空间显示在页面上,这样就不用去服务器查看了,方便

两个办法

 File file = new File("D:");
long totalSpace = file.getTotalSpace();
long freeSpace = file.getFreeSpace();
long usedSpace = totalSpace - freeSpace;
System.out.println("总空间大小 : " + totalSpace / 1024 / 1024 / 1024 + "G");
System.out.println("剩余空间大小 : " + freeSpace / 1024 / 1024 / 1024 + "G");
System.out.println("已用空间大小 : " + usedSpace / 1024 / 1024 / 1024 + "G");
}
}

方法2:

 File diskPartition = new File("D:");
long totalCapacity = diskPartition.getTotalSpace();
long freePartitionSpace = diskPartition.getFreeSpace();
long usablePatitionSpace = diskPartition.getUsableSpace();
System.out.println("**** 以M为单位****\n");
System.out.println("总空间大小 : " + totalCapacity / (1024 * 1024) + " MB");
System.out.println("已用空间大小 : " + usablePatitionSpace / (1024 * 1024) + " MB");
System.out.println("剩余空间大小 : " + freePartitionSpace / (1024 * 1024) + " MB");
System.out.println("\n**** 以G为单位 ****\n");
System.out.println("总空间大小 : " + totalCapacity / (1024 * 1024 * 1024) + " GB");
System.out.println("已用空间大小 : " + usablePatitionSpace / (1024 * 1024 * 1024) + " GB");
System.out.println("剩余空间大小 : " + freePartitionSpace / (1024 * 1024 * 1024) + " GB");

JAVA获取磁盘空间的更多相关文章

  1. 16、C++获取磁盘空间的方法

    使用 C# 获取磁盘空间的方法: public async static Task<int> GetFreeSpace() { StorageFolder localFolder = Ap ...

  2. How to get the free disk space in PostgreSQL (PostgreSQL获取磁盘空间)

    Get the current free disk space in PostgreSQL PostgreSQL获取磁盘空间 from eshizhan Here has a simple way t ...

  3. C# 获取磁盘空间大小的方法

    方法一:利用System.IO.DriveInfo.GetDrives方法来获取 /// /// 获取指定驱动器的空间总大小(单位为B) /// /// 只需输入代表驱动器的字母即可 (大写) /// ...

  4. qt 获取磁盘空间大小,cpu利用率,内存使用率

    转自:http://www.qtcn.org/bbs/read-htm-tid-60613.html. 1:封装成一个类,直接调用即可.已经在多个商业项目中使用.2:所有功能全平台 win linux ...

  5. Linux,实时获取磁盘空间

    #include <iostream> #include <stdlib.h> #include <stdio.h> #include <sys/statfs ...

  6. Delphi实现获取磁盘空间大小的方法

    unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ...

  7. 在Golang中获取系统的磁盘空间内存占用

    获取磁盘占用情况(Linux/Mac下有效) import ( "syscall" ) type DiskStatus struct { All uint64 `json:&quo ...

  8. Java API获取topic所占磁盘空间(Kafka 1.0.0)

    很多用户都有这样的需求:实时监控某个topic各分区在broker上所占的磁盘空间大小总和.Kafka并没有提供直接的脚本工具用于统计这些数据. 如果依然要实现这个需求,一种方法是通过监控JMX指标得 ...

  9. 方法:Linux 下用JAVA获取CPU、内存、磁盘的系统资源信息

    CPU使用率: InputStream is = null; InputStreamReader isr = null; BufferedReader brStat = null; StringTok ...

随机推荐

  1. 【转载】objective-c强引用与弱引用

    形象比喻蛮好玩的^_^    __weak 和 __strong 会出现在声明中   默认情况下,一个指针都会使用 __strong 属性,表明这是一个强引用.这意味着,只要引用存在,对象就不能被销毁 ...

  2. Django简介以及安装

    目录 前言 Web框架本质 服务器和应用程序 基于第三方模块实现Web框架 Python三大主流Web框架 django flask tornado Django框架介绍 安装 创建项目 创建App ...

  3. Ubuntu下使用SSH 命令用于登录远程桌面

    https://blog.csdn.net/yucicheung/article/details/79427578 问题描述 做DL的经常需要在一台电脑(本地主机)上写代码,另一台电脑(服务器,计算力 ...

  4. BeanUtils工具类copyProperties方法缺点及解决

    使用类为spring-beans:4.3.13release包中的 org.springframework.beans.BeanUtils BeanUtils.copyProperties(Objec ...

  5. 02_springmvc处理器映射器和适配器(补充)

    一.非注解的处理器映射器 HandlerMapping 负责根据request请求找到对应的Handler处理器及Interceptor拦截器,将它们封装在HandlerExecutionChain ...

  6. es6 Promise 异步函数调用

    开发很多的时候需要异步操作,常用的做法就是用回调函数,假如需要一连串的调用,并且后面一个调用依赖前一个返回的结果的时候,就得多层嵌套回调函数,比如下面这种情况: $('.animateEle').an ...

  7. Region服务器工作原理

  8. Python 编码转换与中文处理

    python 中的 unicode是让人很困惑.比较难以理解的问题. 这篇文章 写的比较好,utf-8是 unicode的一种实现方式,unicode.gbk.gb2312是编码字符集. py文件中的 ...

  9. 【NOIP2013模拟联考7】OSU

    [NOIP2013模拟联考7]OSU 描述 Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: 一共有n次操作,每次操作只有成功与失败之分, ...

  10. Python-可变类型与不可变类型

    可变类型 可以变化的,列表和字典 利用id()函数 查看内存地址 内存地址变化即不可变类型. 内存地址不变化即可变类型 不可变类型 不可以变化的,字符串和数字 字符串内置方法 索引取值 索引切片 成员 ...