0 votes
1 view
in Java by (4.1k 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 (46.1k 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
asked Oct 13, 2019 in Java by Ritik (3.5k points)
0 votes
1 answer
asked Sep 29, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...