2018년 4월 5일 목요일

[Java] Get System Resource Information


1. Get System Resource Information


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public static void systemInfo() {
       Runtime rt = Runtime.getRuntime();
       System.out.println("Processors (core): " + rt.availableProcessors());
       System.out.println("Memory total: " + rt.totalMemory()); 
       System.out.println("Memory free : " + rt.freeMemory());
       System.out.println("Memory max  : " + rt.maxMemory()); //Long.MAX_VALUE: no limit

       File[] roots = File.listRoots();
        for (File root : roots) {
            System.out.println("----------");
            System.out.println("File system root: " + root.getAbsolutePath());
            System.out.println("Total space  (bytes): " + root.getTotalSpace());
            System.out.println("Free space   (bytes): " + root.getFreeSpace());
            System.out.println("Usable space (bytes): " + root.getUsableSpace());
        }
    }


Result:
Processors (core): 4
Memory total: 64487424
Memory free : 62808064
Memory max  : 935854080
----------
File system root: C:\
Total space  (bytes): 67658473472
Free space   (bytes): 11909046272
Usable space (bytes): 11909046272
----------
File system root: D:\
Total space  (bytes): 51312062464
Free space   (bytes): 14186405888
Usable space (bytes): 14186405888


댓글 없음:

댓글 쓰기