java Runtime类

[java] view plain copy
 
  1. package com.ylchou.testRuntime;  
  2.   
  3. public class TestRuntime {  
  4.   
  5.     public static void main(String[] args) {  
  6.         Runtime rt = Runtime.getRuntime();  
  7.         System.out.println("处理器数量:"+rt.availableProcessors());  
  8.         System.out.println("空闲内存:"+rt.freeMemory()/1024/1024 + "M");  
  9.         System.out.println("总内存:"+rt.totalMemory()/1024/1024 + "M");  
  10.         System.out.println("最大可用内存:"+rt.maxMemory()/1024/1024 + "M");  
  11.           
  12.         try{  
  13.             rt.exec("notepad.exe");  
  14. //            rt.exec("notepad");//后缀.exe可有可无  
  15. //            rt.exec("mspaint");  
  16. //            rt.exec("C:\\Users\\Public\\Desktop\\有道词典.lnk");  
  17. //            rt.exec("services.msc");  
  18. //            rt.exec("cmd");  
  19.         }catch(Exception e){  
  20.             e.printStackTrace();  
  21.         }finally{  
  22.             System.out.println("出现异常啦!");  
  23.         }  
  24.     }  
  25. }  



/**
 *     处理器数量:2
 *    空闲内存:15M
 *    总内存:15M
 *    最大可用内存:247M
 *    出现异常啦!
 */

posted @ 2016-12-06 13:39  天涯海角路  阅读(88)  评论(0)    收藏  举报