1

Is there an simple way to get Windows OS build version (like 16299, 15063 etc) in JAVA? enter image description here

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.

Sig
  • 123
  • 11

1 Answers1

0

As Java is platform-independent, it has no API to get information specific to a certain platform.
However, If you know how to do it in C, you could use JNI.

Yoav Gur
  • 1,366
  • 9
  • 15