java 系統自動檢測
To detect the OS (operating system) name in Java, we use the getProperties() method, which is defined in System class, while calling the method, we need to pass the property name to get the OS (operating system name).
要檢測Java中的OS(操作系統)名稱 ,我們使用System類中定義的getProperties()方法 ,在調用該方法時,我們需要傳遞屬性名稱以獲取OS(操作系統名稱)。
The property to get the OS name is: "os.name"
獲取操作系統名稱的屬性是: “ os.name”
The method call is: System.getProperties("os.name");
方法調用為: System.getProperties(“ os.name”);
Java code to detect and print the OS (operating system) name
用于檢測和打印OS(操作系統)名稱的Java代碼
// Java program to demonstrate the example of
// getProperties() method of System Class
import java.lang.*;
import java.util.Properties;
public class Main {
public static void main(String[] args) {
String os_name = null;
os_name = System.getProperty("os.name");
System.out.println("OS name is: " + os_name);
}
}
Output
輸出量
OS name is: Linux
翻譯自: https://www.includehelp.com/java/how-to-detect-the-os-operating-system-name-in-java.aspx
java 系統自動檢測