I'm trying to get Ubuntu version using Java, but there is a problem.
When using the System.getProperty("os.version"), it's return the kernel version.
You can run any terminal command (like lsb_release -a) inside a Java class with
Runtime.getRuntime().exec("lsb_release -a");
And parse the output
EDIT: Clear solution
String[] args = new String[] {"/bin/bash", "-c", "lsb_release -r", "with", "args"};
Process proc = new ProcessBuilder(args).start();
Note: You need to use lsb_release -r to get only the version.
Here is a snippet to achieve your goal:
String version = (new BufferedReader(new InputStreamReader((new ProcessBuilder("lsb_release", "-rs")).start().getInputStream()))).readLine();
System.out.println(version);
Those two lines display something like that:
14.04
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With