获取系统版本,判断是windows还是Linux

时间:2023-03-08 23:45:47
获取系统版本,判断是windows还是Linux
package com.foresee.zxpt.common.utils;

import java.util.Properties;

/**
* 获取系统版本
* @author GZ
*
*/
public class OSUtils { /**
* 判断是否是Linux
* @return
*/
public static boolean isOSLinux() {
Properties prop = System.getProperties(); String os = prop.getProperty("os.name");
if (os != null && os.toLowerCase().indexOf("linux") > -1) {
return true;
} else {
return false;
}
} /**
* 判断是否是windows
* @return
*/
public static boolean isOSWin() {
Properties prop = System.getProperties(); String os = prop.getProperty("os.name");
if (os != null && os.toLowerCase().startsWith("win")) {
return true;
} else {
return false;
}
}
}
x
42
        String os = prop.getProperty("os.name");
1
package com.foresee.zxpt.common.utils;
2

3
import java.util.Properties;
4

5
/**
6
 * 获取系统版本
7
 * @author GZ
8
 *
9
 */
10
public class OSUtils {
11

12
    /**
13
     * 判断是否是Linux
14
     * @return
15
     */
16
    public static boolean isOSLinux() {
17
        Properties prop = System.getProperties();
18

19
        String os = prop.getProperty("os.name");
20
        if (os != null && os.toLowerCase().indexOf("linux") > -1) {
21
            return true;
22
        } else {
23
            return false;
24
        }
25
    }
26
    
27
    /**
28
     * 判断是否是windows
29
     * @return
30
     */
31
    public static boolean isOSWin() {
32
        Properties prop = System.getProperties();
33
        
34
        String os = prop.getProperty("os.name");
35
        if (os != null && os.toLowerCase().startsWith("win")) {
36
            return true;
37
        } else {
38
            return false;
39
        }
40
    }
41
}
42