有時候,我們在寫業務邏輯的時候,需要判斷一下當前程序所在的操作系統是什么??
然后根據所在不同的操作系統,做不同的業務邏輯處理。
程序代碼
? public static void main(String[] args) {
? ? ? ? String os = System.getProperty("os.name");
? ? ? ? //Windows操作系統
? ? ? ? if (os != null && os.toLowerCase().startsWith("windows")) {
? ? ? ? ? ? System.out.println(String.format("當前系統版本是:%s", os));
? ? ? ? } else if (os != null && os.toLowerCase().startsWith("linux")) {//Linux操作系統
? ? ? ? ? ? System.out.println(String.format("當前系統版本是:%s", os));
? ? ? ? } else { //其它操作系統
? ? ? ? ? ? System.out.println(String.format("當前系統版本是:%s", os));
? ? ? ? }
? ? }
運行效果