Created
April 13, 2018 13:58
-
-
Save navopw/327241389ce652e12ecb5b759deea70a to your computer and use it in GitHub Desktop.
OSDetector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OSDetector { | |
public static OperatingSystem getOperatingSystem() { | |
//Der Name vom Betriebssystem kann aus den System Eigenschaften gelesen werden (Unter os.name) | |
String osName = System.getProperty("os.name").toLowerCase(); | |
//Enthält der osName "win", so ist das Betriebssystem Windows | |
if (osName.contains("win")) { | |
return OperatingSystem.WINDOWS; | |
} | |
//Enthält der osName "nix", "nux" oder "aix", so ist das Betriebssystem Linux/Unix | |
if (osName.contains("nix") || osName.contains("nux") || osName.contains("aix")) { | |
return OperatingSystem.UNIX; | |
} | |
//Enthält der osName "mac", so ist das Betriebssystem Mac OS | |
if (osName.contains("mac")) { | |
return OperatingSystem.MAC; | |
} | |
//Ansonsten ist es ein uns unbekanntes Betriebssystem wie z.B. Solaris oder TempleOS ;) | |
return OperatingSystem.UNKNOWN; | |
} | |
public enum OperatingSystem { | |
WINDOWS, UNIX, MAC, UNKNOWN; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment