angelblade27
asked on
finding the os
is there someway for java to know which OS it is running on ( ie linux or windows)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
public static OperatingSystem getOperatingSystem() {
if (os != null)
return os;
if (System.getProperty("mrj.v
os = new MacOS();
} else {
String osName = System.getProperty("os.nam
if (osName.indexOf("Windows")
os = new Windows();
} else if(osName.indexOf("OS/2") != -1) {
os = new OS2();
} else if(osName.indexOf("VMS") != -1) {
os = new VMS();
} else {
os = new Unix();
}
}
return os;
}
Of course you can return enums, or constants in stead of classes implementing OperatingSystem, but it's just better practice if you want to define custom behaviour depending on the OS.