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?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Below code shows the values that you can get from System API, these all things you can get through this API.
Answers:-
You can just use sun.awt.OSInfo#getOSType() method
The following JavaFX classes have static methods to determine current OS (isWindows(),isLinux()...):
Example:
I find that the OS Utils from Swingx does the job.
You can use:
P.S. You may find this code useful:
All it does is print out all the properties provided by your Java implementations. It'll give you an idea of what you can find out about your Java environment via properties. :-)
I liked Wolfgang's answer, just because I believe things like that should be consts...
so I've rephrased it a bit for myself, and thought to share it :)