admin 管理员组

文章数量: 887021

判断一个系统是windows还是linux

package com.zhang.systemdemo;

import org.junit.jupiter.api.Test;

/**
 * @description: 判断运行的系统是windows还是linux
 * @author: zhangyu
 */
public class JudgeSystem {
    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);
    }
}

本文标签: 系统 java Windows Linux