Reputation: 3
I am looking for a method or package in java where we can get OS level Information.
Is there any package equivalent to Management Object Searcher(c#) in java?
Upvotes: 0
Views: 688
Reputation: 2272
You can get OS and it version by using below code snippet:
String OS = System.getProperty("os.name");
System.out.println("Your OS is : " + OS);
String OSVersion = System.getProperty("sun.arch.data.model");
System.out.println("Your OS version is : " + OSVersion + " bit");
Upvotes: 0
Reputation: 757
Use this method in your code know the OS
os.name
os.version
os.arch
Upvotes: 0
Reputation: 3462
One simple line of code can do this.
System.getProperty("os.name");
and more specifically what OS level info you are looking ?
For memory related stuff you can have something like this.
System.out.println("Free memory (bytes): " +
Runtime.getRuntime().freeMemory());
long maxMemory = Runtime.getRuntime().maxMemory();
System.out.println("Total memory (bytes): " +
Runtime.getRuntime().totalMemory());
Thanks
Upvotes: 1
Reputation: 136012
Get OperatingSystemMXBean
with
java.lang.management.ManagementFactory
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
get OS version or other available info.
Upvotes: 0
Reputation: 68715
If you know which OS native library you need to get the information you desire then call it using JNI.
Upvotes: 0