Is there a way for a java program (or more specifically java in jsp) to find out which platform (windows or linux) it is currently running in? Thanks in advance.
views:
130answers:
5System.getProperty("os.name")
For other similar properties and their descriptions, see java.lang.System
The question is what you need this for. The usual approach is asking on the values of system properties, which are not well defined, and may break if you for some reason need to choose another JVM or another platform.
Another approach is actually testing the underlying platform for the functionality you need to know how works during startup. I.e. if you want to know if you can remove a file that is open or not, then write a small snippet testing for that. If you want to know if the file system is case sensitive, then write a snippet testing for that.
This will make your code more robust in the long run.
If you do want to use System.getProperty("os.name")
to identify the environment, then you may be interested in a list of identifiers used by the company formerly known as SUN