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

两个办法

 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. JWT生成token

    1.JWT简介 JSON Web Token 简称JWT.一个JWT实际上就是一个字符串,它由三部分组成,头部.载荷与签名.JWT生成的token是这样的 2.Json Web Token(JWT)生 ...

  2. 杂项-公司:AT&T

    ylbtech-杂项-公司:AT&T AT&T公司(英语:AT&T Inc.,原为American Telephone & Telegraph的缩写,也是中文译名美国电 ...

  3. C++ 连接上期所CTP交易行情接口

    CTP相关接口和文档下载: http://www.simnow.com.cn/static/softwareDownload.action 相关库文件以及头文件如下: 遇到的问题: 1.运行直接退出了 ...

  4. PAT甲级——A1003Emergency

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  5. 《DSP using MATLAB》Problem 7.38

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  6. python tkiner实现自动打包程序

    环境 python3.x 使用前请确保安装pyinstaller库 本程序还未完善,可以自行完善 若要使用加密,请自行安装cryptodome库 import tkinter as tk from t ...

  7. HBase 概念视图

  8. Ubuntu 14.04 Ruby 2.3.3 安装

    在Ubuntu 14.04通过下载Ruby源码包进行安装. 第一步,更新apt-get sudo apt-get update 通过apt-get安装ruby依赖 sudo apt-get insta ...

  9. iftop实时监控网络流量

    需要安装,linux自身不自带该命令 中间的<= =>这两个左右箭头,表示的是流量的方向. TX:发送流量 RX:接收流量 TOTAL:总流量 Cumm:运行iftop到目前时间的总流量 ...

  10. md5密码入库

    <?php //连接数据库 $pdo = new PDO('mysql:host=localhost;dbname=md5;charset=UTF8', 'root', ''); # 设置为fa ...