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 ...
随机推荐
- day1-字符串、列表
字符串操作: name = "Wills Qian" # 创建字符串变量 print(len(name)) # 打印字符串长度 print(name[0]) # 提取第一个字符W ...
- 服务器迁移部署OmsEdi
基本配置 绑定 高级设置
- 转:五种I/O模型和select函数简介
源地址:http://blog.csdn.net/jnu_simba/article/details/9070955 一.五种I/O模型 1.阻塞I/O 我们在前面所说的I/O模型都是阻塞I/O,即调 ...
- 【核心核心】5.Spring【DI】注解方式
使用注解的方式依赖注入不用提供set方法 1.普通类型的注解 @Value @Value(value="春天") private String name; 2.对象类型的注解 @A ...
- 如何使用log4j记录日志
1.下载jar包 http://logging.apache.org/log4j 2.将jar包加入项目 放在lib(没有就创建)下 对已经复制过来的jar包鼠标点击右键,选中BuildPath - ...
- Django项目:CRM(客户关系管理系统)--73--63PerfectCRM实现CRM讲师下载作业
# teacher_urls.py # ————————62PerfectCRM实现CRM讲师讲课记录———————— from django.conf.urls import url from bp ...
- poj 2288
传送门 解题思路 状压dp,记录路径条数,dp[S][i][j]表示状态为S,前一个点是i,再前一个点是j的最大值,然后在开个一样的数组记录方案数,时间复杂度O(2^n*n^2),注意要用long l ...
- 微信小程序slider应用,可加减的slider控制
<view class="control-w "> <block wx:for="{{controls}}" wx:key="id& ...
- OpenCASCADE动画功能
OpenCASCADE动画功能 eryar@163.com 1.Introduction OpenCASCADE提供了类AIS_Animation等来实现简单的动画功能. 从其类图可以看出,动画功能有 ...
- react-native start停止在Loading dependency graph, done.
在试验的过程中. 发现运行 react-native start会卡住,停留在Loading dependency graph, done. 原因大概是之前运行过 react-native run-a ...