古詩詞大全網 - 成語用法 - java 如何判斷操作系統是Linux還是Windows

java 如何判斷操作系統是Linux還是Windows

java判斷操作系統是Linux還是Windows可以用getProperty方法進行判斷

工具:

eclipse

代碼如下:

public?class?HelloWorld?{

public?static?void?main(String[]?args)?{

System.out.println("該系統為:"+System.getProperties().getProperty("os.name"));

}

}

效果圖如下:

說明:

System類

public static?Properties?getProperties()

將?getProperty(String)?方法使用的當前系統屬性集合作為?Properties?對象返回