How to retrieve available RAM from Windows command line?

前端 未结 11 809
-上瘾入骨i
-上瘾入骨i 2020-12-23 09:44

Is there a command line utility within Windows or third-party program that can retrieve available RAM on a machine? (Since I don\'t believe this can be done in pure JAVA, si

11条回答
  •  眼角桃花
    2020-12-23 10:22

    This cannot be done in pure java. But you can run external programs using java and get the result.

    Process p=Runtime.getRuntime().exec("systeminfo");
    Scanner scan=new Scanner(p.getInputStream());
    while(scan.hasNext()){
        String temp=scan.nextLine();
        if(temp.equals("Available Physical Memmory")){
           System.out.println("RAM :"temp.split(":")[1]);
           break;
        }
    }
    

提交回复
热议问题