1. 程式人生 > >獲取系統版本,判斷是windows還是Linux

獲取系統版本,判斷是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