Okay im working on a java program which will get peoples system info and save it to a text file so i can help them with problems (designed for members of my family to use as i seem to be their own personal IT guy lol)

package sysinfo;
import java.io.*;

public class Main {

    public Main()


  public static void main(String[] args)
    System.out.println("JAVA SYSTEM INFORMATION PROGRAM");
    System.out.println("Java Runtime Information.");
    System.out.println(System.getProperty("java.runtime.name") + " version " + System.getProperty("java.runtime.version") + System.getProperty("java.vm.version") + " by " + System.getProperty("java.vm.vendor"));
    System.out.println("Execution Directory: " + System.getProperty("user.dir"));

    System.out.println("OS / Platform Information.");
    System.out.println("OS appears to be: " + System.getProperty("os.name") + " Version " + System.getProperty("os.version") + " on " + System.getProperty("os.arch") + " architechture");
    System.out.println("Number of (Logical) CPUs available: " + Runtime.getRuntime().availableProcessors());

    System.out.println("User Information.");
    System.out.println("User: " + System.getProperty("user.name") + " has a home directory at: " + System.getProperty("user.home"));
    System.out.println("Desktop environment appears to be: " + System.getProperty("sun.desktop"));

    File[] roots = File.listRoots();

    System.out.println("Filesystem Information.");
    System.out.println("Temp directory is: " + System.getProperty("java.io.tmpdir"));
    for (File root : roots)
      System.out.println("File system root path: " + root.getAbsolutePath());
      System.out.println("Total space (Megabytes): " + root.getTotalSpace() / 1048576);
      System.out.println("Usable space (Megabytes): " + root.getUsableSpace() / 1048576);


Got this far, but im after some more info like total RAM, free ram, (only seem to be able to find out how much is available to the JRE itself) as well as CPU make/model and network info like IP.

Is there a portable way to do this? Linux/Windows/OSX?

Recommended Answers

All 5 Replies

Get IP is not difficult you can see it from this example.
Memory can be done as follows

import java.lang.management.ManagementFactory;

public class MemorySize {

    public static void main(String[] args){
    	com.sun.management.OperatingSystemMXBean mxbean = 
    		(com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
		System.out.println(mxbean.getTotalPhysicalMemorySize() + " Bytes "); 

you can even get the size of the Java Memory Heap

As for processor, it does not seem that Sun fixed the bug as mentioned in this post. If you really hot after some CPU info have look at Interfacing VC++, Java, and Assembly. If anyone has better info on this please correct me.

PS: OS info can be retried also as

System.out.println("Returns the operating system architecture. "+ManagementFactory.getOperatingSystemMXBean().getArch()); 
System.out.println("Returns the operating system name. "+ManagementFactory.getOperatingSystemMXBean().getName());
System.out.println("Returns the operating system version. "+ManagementFactory.getOperatingSystemMXBean().getVersion());

Yeah RE the cpu i was thinking of querying /proc/cpuinfo on linux, and perhaps trying to link to a C dll to get it working on linux

You can save yourself some typing if you want to list all of the properties available through System.getProperties()


Yeah i tried that but i didnt like the format, and didnt need all the info.

Yeah i tried that but i didnt like the format, and didnt need all the info.

From that **I assume** the output already contains whatever information you needed.

Well honestly jbennet I didnt expect to be saying this to a Moderator but just a little R & D (a little bit of googling or looking up the javadocs) on what the "System.getProperties()" method returns and a little more effort on figuring how to parse and selectively print the contents of a java.util.Properties object could fetch you the answer you desire.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.