Java获取当前内存及硬盘使用情况
import java.io.File;
import java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean; public class MemDisk
{
public static void main(String[] args)
{
getMemInfo();
System.out.println();
getDiskInfo();
} public static void getDiskInfo()
{
File[] disks = File.listRoots();
for(File file : disks)
{
System.out.print(file.getPath() + " ");
System.out.print("空闲未使用 = " + file.getFreeSpace() / 1024 / 1024 + "M" + " ");// 空闲空间
System.out.print("已经使用 = " + file.getUsableSpace() / 1024 / 1024 + "M" + " ");// 可用空间
System.out.print("总容量 = " + file.getTotalSpace() / 1024 / 1024 + "M" + " ");// 总空间
System.out.println();
}
} public static void getMemInfo()
{
OperatingSystemMXBean mem = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
System.out.println("Total RAM:" + mem.getTotalPhysicalMemorySize() / 1024 / 1024 + "MB");
System.out.println("Available RAM:" + mem.getFreePhysicalMemorySize() / 1024 / 1024 + "MB");
} }
Java获取当前内存及硬盘使用情况的更多相关文章
- C/C++获取Linux系统CPU和内存及硬盘使用情况
需求分析: 不使用Top df free 等命令,利用C/C++获取Linux系统CPU和内存及硬盘使用情况 实现: //通过获取/proc/stat (CPU)和/proc/meminfo(内存 ...
- C/C++获取Windows系统CPU和内存及硬盘使用情况
//1.获取Windows系统内存使用率 //windows 内存 使用率 DWORD getWin_MemUsage(){ MEMORYSTATUS ms; ::GlobalMemoryStatus ...
- Java获取虚拟机内存和操作系统内存及其线程
为什么要获取虚拟机内存和操作系统内存呢? 虚拟机内存,这里主要指JVM.为了防止有的时候因为JVM内存问题导致服务器宕机,所以有必要监控JVM的内存.当达到一定值时,通过邮件及时通知,防止线上宕机造成 ...
- linux查看系统CPU,内存,硬盘使用情况
top查看CPU,内存使用情况 free查看硬盘使用情况
- Unity3D研究院编辑器之脚本获取资源内存和硬盘大小
内存 使用Profiler可以查看某个资源的内存占用情况,但是必须启动游戏,并且待查看的资源已经载入游戏中.我希望的是不启动游戏,也能看到它的内存好做统计. 硬盘 由于unity中的资源压缩格式记录在 ...
- JAVA获取计算机CPU、硬盘、主板、网络等信息
通过使用第三方开源jar包sigar.jar我们可以获得本地的信息 1.下载sigar.jar sigar官方主页 sigar-1.6.4.zip 2.按照主页上的说明解压包后将相应的文件copy到j ...
- Linux c获取任意路径的硬盘使用情况
没有什么好说的,其实就是获取硬盘的statfs信息结构 代码如下: #include <stdio.h> #include <stdlib.h> #include <sy ...
- Java 获取JVM内存和物理内存信息
package com.sysinfo; public class MonitorInfo { /** jvm可使用内存. */ private long totalMemory; /** jvm剩余 ...
- linux查看 cpu及内存和硬盘使用情况的命令top
使用时输入 top,退出时输入q http://www.cnblogs.com/ggjucheng/archive/2012/01/08/2316399.html 简介 top命令是Linux下常用的 ...
随机推荐
- java Direct Buffer
public static ByteBuffer allocate (int capacity) //性能低于下面的Direct,因为是把内存建立在JVM堆上,容易被GC回收,可能需要多次 ...
- [LeetCode]题解(python):098 Validate Binary Search Tree
题目来源 https://leetcode.com/problems/validate-binary-search-tree/ Given a binary tree, determine if it ...
- [LeetCode]题解(python):091 Decode Ways
题目来源 https://leetcode.com/problems/decode-ways/ A message containing letters from A-Z is being encod ...
- Emmet(之前叫Zencoding)插件安装
按 ctr+shift+P,输入 install Package,找到emmet,确认安装 Package Control Messages======================== Emmet ...
- A Framework for Programme Management
In business today organisations manage multiple projects concurrently with shared or overlapping res ...
- MVC中的@Html.DisplayFor如何控制日期的显示格式
在Sql Server中,如果将某字段定义成日期 时间 类型DateTime,那么在视图中会默认显示成年月日时分秒的方式(如 2013/8/6 13:37:33) 如果只想显示成年月日或者其他自定义形 ...
- 树莓派连接wifi
使用树莓派,通过无线网卡连接wifi,再通过远程桌面或者ssh的连接树莓派比较方便,本文记录树莓派wifi如何设置. 参考链接: http://www.jianshu.com/p/b42e8d3df4 ...
- JS-JQ实现TAB选项卡
原理: 有两种实现方法, 方法一利用css的display:none 和display:block:交替实现: 方法二利用css的z-index:
- [代码片段]OSTU算法
用在片上系统上的 //OSTU求图像的阈值 u8 otsuThreshold(u8 **img, u16 height, u16 width) { // int width = frame->w ...
- NavigationController popToViewController跳转之前任意ViewController方法
NSArray *viewControllers = self.navigationController.viewControllers;A *viewController = [viewContro ...