张慧的博客

张慧的博客

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  45 Posts :: 0 Stories :: 24 Comments :: 0 Trackbacks

在java中经常需要获取一些系统信息,如系统的资源空间等。下面就是一些Runtime的应用:


public static void main(String[] a){
         Runtime runtime 
= Runtime.getRuntime();
         
long freeMemoery = runtime.freeMemory();
         
long totalMemory = runtime.totalMemory();
         
long usedMemory = totalMemory - freeMemoery;
         
long maxMemory = runtime.maxMemory();
         
long useableMemory = maxMemory - totalMemory + freeMemoery;
         
         System.out.println(
"当前时间:"+runtime);
         System.out.println(
"系统闲置空间:"+freeMemoery);
         System.out.println(
"系统总空间:"+totalMemory);
         System.out.println(
"系统被用的空间:"+usedMemory);
         System.out.println(
"系统最大空间:"+maxMemory);
         System.out.println(
"系统可用空间:"+useableMemory);
     }

运行效果:


当前时间:java.lang.Runtime@c3c749
 系统闲置空间:
4873672
 系统总空间:
5177344
 系统被用的空间:
303672
 系统最大空间:
66650112
 系统可用空间:
66346440

 

posted on 2012-07-08 23:30 张慧 阅读(736) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: