Is there an simple way to get Windows OS build version (like 16299, 15063 etc) in JAVA?
Currently only solution I've found is running external process and parsing the output:
Runtime runtime = Runtime.getRuntime();
Process process;
BufferedReader bufferedReader;
StringBuilder stringBuilder = new StringBuilder();
String stdOutLine = null;
String windowsVersion = null;
try {
process = runtime.exec("cmd.exe /c ver");
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((stdOutLine = bufferedReader.readLine()) != null) {
stringBuilder.append(stdOutLine);
}
} catch (IOException ex) {
throw new RuntimeException("Error while getting Windows version");
}
windowsVersion = Arrays.stream(stringBuilder.toString().split("\\."))
.filter(s -> s.length() == 5 && s.matches("[0-9]+"))
.findFirst()
.get();
Is there another more elegant way of either getting that string or extracting the needed part? Thank you.