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 系统自动检测