Skip to content

Commit

Permalink
operating system judge add
Browse files Browse the repository at this point in the history
  • Loading branch information
developers-youcong committed Oct 23, 2022
1 parent 262d5f3 commit 834f1f6
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.yc.common.core.base.utils;

/**
* @description:
* @author: youcong
*/
public class JudgeSysUtil {

private static final String OS_NAME = "os.name";

private static final String LINUX_SYS = "linux";

private static final String WINDOWS_SYS = "windows";

private static final String OTHER_SYS = "other system";

/**
* Linux
*
* @return
*/
public static boolean isLinux() {
return System.getProperty(OS_NAME).toLowerCase().contains("linux");
}

/**
* Windows
*
* @return
*/
public static boolean isWindows() {
return System.getProperty(OS_NAME).toLowerCase().contains("windows");
}

/**
* 判断当前操作系统
*
* @return
*/
public static String JudgeSystem() {
if (isLinux()) {
return LINUX_SYS;
} else if (isWindows()) {
return WINDOWS_SYS;
} else {
return OTHER_SYS;
}
}

public static void main(String[] args) {
System.out.println("current system is:" + JudgeSysUtil.JudgeSystem());
}
}

0 comments on commit 834f1f6

Please sign in to comment.