java OSの種類を取得する

javaで、OSの種類を取得する手順を記述してます。
環境
- OS windows11 home
- java 17.0.2
手順
OSの種類を取得するには、「System.getProperty」を使用します。
System.getProperty("os.name")
実際に、使用してみます。
public class App {
public static void main(String[] args) throws Exception {
System.out.println(System.getProperty("os.name")); // c:\java\test\src
}
}
取得されていることが確認できます。
またバージョンは「os.version」でアーキテクチャは「os.arc」で取得することも可能です。
public class App {
public static void main(String[] args) throws Exception {
System.out.println(System.getProperty("os.version")); // 10.0
System.out.println(System.getProperty("os.arch")); // amd64
}
}
-
前の記事
フェッチAPIでJavaScriptのリクエストをモダンにこなす 2025.02.14
-
次の記事
Railsのエラー『SystemStackError: stack level too deep』の解決方法 2025.02.17
コメントを書く