Skip to content

Instantly share code, notes, and snippets.

@kodiyan
Created August 7, 2014 18:46
Show Gist options
  • Save kodiyan/f86aba8dd577d469bcd2 to your computer and use it in GitHub Desktop.
Save kodiyan/f86aba8dd577d469bcd2 to your computer and use it in GitHub Desktop.
Detect Operating System using Java
public static String OSDetector () {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) {
return "Windows";
} else if (os.contains("nux") || os.contains("nix")) {
return "Linux";
}else if (os.contains("mac")) {
return "Mac";
}else if (os.contains("sunos")) {
return "Solaris";
}else {
return "Unkonwn OS";
}
}
@kodiyan
Copy link
Author

kodiyan commented Aug 7, 2014

This is to determine Operating System name using Java. This will return name of OS for MAC, Linux, Windows and Solaris.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment