Can I know the operating system by code in Java?

Asked 2 years ago, Updated 2 years ago, 45 views

I'm making a program When the program is running, it's like Unix or Windows I want to know the operating system of the host, is this possible? Isn't there a 100% reliable way?

java

2022-09-22 22:30

1 Answers

Use System.getProperty("os.name") to do it.

class ShowProperties {
    public static void main(String[] args) {
        System.getProperties().list(System.out);
    }
}

You can write it like this.


2022-09-22 22:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.