Is there any way to find os name using java ?
I have tried below code, but it will returns looks like (Linux , windows..)
System.getProperty("os.name")
I need to detecting below format
Linux – “ubuntu, mandriva .. ” , windows – “xp,vista …”
sorry for my English 🙁 !!!
Any idea ?
You can use
System.getProperty()to get the following properties:os.name: Operating system nameos.arch: Operating system architectureos.version: Operating system versionIn your case, I believe you’re looking for the
os.versionproperty. The javadocs forSystem.getProperties()contain a full list of properties that you can retrieve.Edit
I just tested this in Linux Mint and it appears that the getting the
os.versionproperty actually returns the kernel version, and not the distro version:After finding this post, it seems as though there’s no reliable way to find which Linux distribution you’re running through the Java API.
If you know you’re running in Linux, you can instead run one of the following system commands from Java, but you’ll have to grep/parse out the distribution:
cat /etc/*-release