Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

OS Detection

  Asked By: Maria    Date: Nov 27    Category: Java    Views: 725
  

Maybe this is a feature than's not suppose to be part of Java, but
I'd like to detect the operating system the JVM is running on.
Anyone have any sample code that does this?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Vicki Fields     Answered On: Nov 27

use System.getProperty(String key). Look at the docs for System class to see
all the keys. This will show your OS name, architecture and version:

public class GetProperties {
public static void main(String [] args) {
System.out.println(System.getProperty("os.name"));
System.out.println(System.getProperty("os.arch"));
System.out.println(System.getProperty("os.version"));
}
}

 
Didn't find what you were looking for? Find more on OS Detection Or get search suggestion and latest updates.




Tagged: