Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which OS is the java program running in?

Status
Not open for further replies.

Stevoie

Programmer
Jun 7, 2001
68
IE
How can a java program find out what OS (mac, Win, linux) it's running under
Thanx
 
You can use "System.getProperty(os.name)". Else if you just say "System.getProperties()", will return you all the system property including OS name.
 
You can use the following example.
1. To get os name
public class EnvVar {
public static void main(String args[]) {
String s =
System.getProperty("user.name");
System.out.println(s);
}
}

2. To get all the properties

import java.util.Properties;
public class EnvVar {
public static void main(String args[]) {
Properties p = System.getProperties();
p.list(System.out);
}
}

Hope this helps you.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top