[Q#10008527][A#10008565] How to get operating system in Java
https://stackoverflow.com/q/10008527
I know there is such a question on SO, but I could not find it. So asking again… I need to set up properties to my program, but I need to make it OS indipendent - running both on Windows XP and Linux (unknown distro, unknown version) More specifically - I need to set up to the system where to find the chromedriver binary. I need something like this pseudocode: Now I need the part for getting the OS. Thanks for help.
Answer
https://stackoverflow.com/a/10008565
APIzation
System.getProperty("os.name");
System.getProperty("os.version");
System.getProperty("os.arch");
package com.stackoverflow.api;
public class Human10008565 {
public static String getOperatingSystem() {
return (
System.getProperty("os.name") +
" " +
System.getProperty("os.version") +
" " +
System.getProperty("os.arch")
);
}
}
package com.stackoverflow.api;
/**
* How to get operating system in Java
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/10008565">https://stackoverflow.com/a/10008565</a>
*/
public class APIzator10008565 {
public static void getSystem() throws Exception {
System.getProperty("os.name");
System.getProperty("os.version");
System.getProperty("os.arch");
}
}