0
点赞
收藏
分享

微信扫一扫

springMvc47-java判断系统是linux还是windows系统


判断一个系统是windows还是linux?

     

import org.junit.jupiter.api.Test;

/**
* @program: utilsdemo
* @description: 判断运行的系统是windows还是linux
* @author: zhangyu
* @create: 2019-08-12 10:07
*/

public class JudgeSystem {

/**
* @description: 判断运行的系统是不是linux
* @author: zhangyu
* @create: 2019-08-12
*/

public static boolean isLinux() {

return System.getProperty("os.name").toLowerCase().contains("linux");

}

public static boolean isWindows() {

return System.getProperty("os.name").toLowerCase().contains("windows");

}

public String JudgeSystem() {

if (isLinux()) {

return "linux";

} else if (isWindows()) {

return "windows";

} else {

return "other system";

}

}

@Test

public void fun() {

boolean flag1 = isLinux();

// System.out.println(flag1);

boolean flag2 = isWindows();

// System.out.println(flag2);

// System.out.println(System.getProperty("os.name"));

String sys = JudgeSystem();

System.out.println(sys);

}

}

举报

相关推荐

0 条评论