How to get size of disc and size of RAM in JAVA

Posted By: Matpal - December 30, 2016
Following code can help you to find size of the disc and size of the RAM. 
import java.lang.management.*;
import java.io.*;

class Main
{
    public static void main(String... a)
    {
        long diskSize = new File("/").getTotalSpace();

        long maxMemory = Runtime.getRuntime().maxMemory();
        long memorySize = ((com.sun.management.OperatingSystemMXBean) 
ManagementFactory.getOperatingSystemMXBean())
.getTotalPhysicalMemorySize();
        System.out.println("Size of C:="+diskSize+" Bytes");


        System.out.println("RAM Size="+memorySize+" Bytes");
   }
}

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.