如何在Java中检测OS(操作系统)名称?
要检测Java中的OS(操作系统)名称,我们使用getProperties()System类中定义的方法,在调用该方法时,我们需要传递属性名称以获取OS(操作系统名称)。
获取操作系统名称的属性是:“os.name”
方法调用为:System.getProperties(“os.name”);
用于检测和打印OS(操作系统)名称的Java代码
//Java程序演示的例子
//getProperties()系统类的方法
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);
}
}输出结果
OS name is: Linux
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短