java OBTENER OS

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java OBTENER OS相关的知识,希望对你有一定的参考价值。

//OBTENER EL OS DONDE SE EJCUTA EL CODIGO JAVA
String os = System.getProperty("os.name").toLowerCase();

//Validacion para win o linux
if (isWindows()) {
		System.out.println("This is Windows");
	} else if (isUnix()) {
		System.out.println("This is Unix or Linux");
	}
}
//Metodos
//windows
public static boolean isWindows() {
  return (os.indexOf("win") >= 0);
}
//Linux
public static boolean isLinux() {
  return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 );
}

以上是关于java OBTENER OS的主要内容,如果未能解决你的问题,请参考以下文章