簡體   English   中英

如何從客戶端程序獲取操作系統名稱?

[英]How do I get the os name from the client program?

程序的某些部分受操作系統類型的影響。 所以我嘗試按操作系統名稱分支如下。 當我在本地運行它時,它可以工作。 但是將其上傳到服務器后,我將其作為客戶端程序運行,看來它無法獲得操作系統名稱。 請讓我知道如何從客戶端程序獲取操作系統名稱。 謝謝。

public void getOSName() {   
   String osName = System.getProperty("os.name")
   if(!osName.trim().toUpperCase().equals("WINDOWS 10")){
   run();        
   }else{
   }
}

在util類下簽出以進行OS驗證。

使用系統屬性:由於此問題,此方法可能會失敗。 請參閱Windows 10的Java的“ os.name”?

/**
 * The Class OSValidator.
 */
public final class OSValidator {

    /** The Constant OS. */
    public static final String OS = System.getProperty("os.name").toLowerCase();

    /**
     * Checks if is windows 7.
     *
     * @return true, if is windows 7
     */
    public static final boolean isWindows7() {
        return (OS.indexOf("windows 7") >= 0);
    }

    /**
     * Checks if is windows 10.
     *
     * @return true, if is windows 10
     */
    public static final boolean isWindows10() {
        return (OS.indexOf("windows 10") >= 0);
    }

    /**
     * Checks if is mac.
     *
     * @return true, if is mac
     */
    public static final boolean isMac() {
        return (OS.indexOf("mac") >= 0);
    }
}

使用SystemUtils – Apache Commons Lang

public String getOperatingSystemSystemUtils() {
    String os = SystemUtils.OS_NAME;
    // System.out.println("Using SystemUtils: " + os);
    return os;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM