java check if current operating system is linux or windows

Java
[Edit]
+
0
-
0

Java check if current operating system is linux or windows

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
public class SystemUtils { public static void main(String[] args) { // if we run this util on Linux eg Ubuntu, Debian, CentOS System.out.println(isLinux()); // true } public static boolean isLinux() { String name = System.getProperty("os.name"); return name.toLowerCase().contains("linux"); } public static boolean isWindows() { String name = System.getProperty("os.name"); return name.toLowerCase().contains("win"); } }