JAVA获取磁盘空间
需要把磁盘空间显示在页面上,这样就不用去服务器查看了,方便
两个办法
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获取磁盘空间的更多相关文章
- 16、C++获取磁盘空间的方法
使用 C# 获取磁盘空间的方法: public async static Task<int> GetFreeSpace() { StorageFolder localFolder = Ap ...
- 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 ...
- C# 获取磁盘空间大小的方法
方法一:利用System.IO.DriveInfo.GetDrives方法来获取 /// /// 获取指定驱动器的空间总大小(单位为B) /// /// 只需输入代表驱动器的字母即可 (大写) /// ...
- qt 获取磁盘空间大小,cpu利用率,内存使用率
转自:http://www.qtcn.org/bbs/read-htm-tid-60613.html. 1:封装成一个类,直接调用即可.已经在多个商业项目中使用.2:所有功能全平台 win linux ...
- Linux,实时获取磁盘空间
#include <iostream> #include <stdlib.h> #include <stdio.h> #include <sys/statfs ...
- Delphi实现获取磁盘空间大小的方法
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ...
- 在Golang中获取系统的磁盘空间内存占用
获取磁盘占用情况(Linux/Mac下有效) import ( "syscall" ) type DiskStatus struct { All uint64 `json:&quo ...
- Java API获取topic所占磁盘空间(Kafka 1.0.0)
很多用户都有这样的需求:实时监控某个topic各分区在broker上所占的磁盘空间大小总和.Kafka并没有提供直接的脚本工具用于统计这些数据. 如果依然要实现这个需求,一种方法是通过监控JMX指标得 ...
- 方法:Linux 下用JAVA获取CPU、内存、磁盘的系统资源信息
CPU使用率: InputStream is = null; InputStreamReader isr = null; BufferedReader brStat = null; StringTok ...
随机推荐
- leetcode146周赛-5130-等价多米诺骨牌对的数量
题目描述: 方法一: class Solution(object): def numEquivDominoPairs(self, dominoes): """ :type ...
- react antd样式按需加载配置以及与css modules模块化的冲突问题
通过create-react-app脚手架生成一个项目 然后运行npm run eject 把webpack的一些配置从react-scripts模块弹射出来, 方便自己手工增减,暴露出来的配置文件在 ...
- FreeMarker 自定义 TemplateDirectiveModel(一)
FreeMarker 是一个用 Java 语言编写的模板引擎,它基于模板来生成文本输出.FreeMarker 与 Web 容器无关,即在 Web 运行时,它并不知道 Servlet 或 HTTP.它不 ...
- 使用Java代码获取Java进程ID的方法
需要jre/lib下的tools.jar包 public class Test { public static void main(String[] args) throws Exception { ...
- Python学习day44-数据库(单表及多表查询)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- ucore 地址映射的几个阶段
第零阶段: 启动之后的实模式阶段 vir = lin = pa 第一阶段 : 启动 bootloader 的段式分页 这里段基址是0 ,所以地址空间维持不变 vir addr = lin addr = ...
- osg::BlendFunc来设置透明度
osg::BlendFunc介绍 混合是什么呢?混合就是把两种颜色混在一起.具体一点,就是把某一像素位置原来的颜色和将要画上去的颜色,通过某种方式混在一起,从而实现特殊的效果. 假设我们需要 ...
- tcpdump 抓包
简介 用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据包的 ...
- Inoic 滚动条问题
1.看图说话 2.没有超过一个页,怎样去掉图中的滚动条? 3修改后预览效果
- AdaBoost笔记之代码
最近要做二分类问题,先Mark一下知识点和代码,参考:Opencv2.4.9源码分析——Boosting 以下内容全部转自此文 一 原理 二 opencv源码 1.先看构建Boosting的参数: ...