Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)

I would like to determine the operating system of the host that my Java program is running programmatically (for example I would like to be able to load different properties based on whether I am on a Windows or Unix platform). What is the safest way to do this with 100% reliability?

1 Answer

0 votes
by (46k points)

You can try this Syntax:

System.getProperty("os.name")

Example:

class ShowProperties {

    public static void main(String[] args) {

        System.getProperties().list(System.out);

    }

}

This code print out all the properties stored by your Java implementations. It'll give you a notion of what you can get out of your Java environment via properties.

Related questions

0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
asked Oct 13, 2019 in Java by Ritik (3.5k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...