Here you can find the source of getJavaVersion(String command)
Parameter | Description |
---|---|
command | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
InterruptedException | an exception |
public static String getJavaVersion(String command) throws IOException, InterruptedException
//package com.java2s; /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { /**// w w w.j a v a2 s . c o m * Retrieves the version of the java vm indicated by the command string. * * @param command * @return * @throws IOException * @throws InterruptedException */ public static String getJavaVersion(String command) throws IOException, InterruptedException { String run_command = "'" + command + "' -version"; System.out.println(run_command); Process p; String[] args = { command, "-version" }; p = Runtime.getRuntime().exec(args); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream())); String line = reader.readLine(); int row = 0; while (line != null) { line = reader.readLine(); if (line.startsWith("Java(TM)")) { if (line.contains("build")) { int start = line.indexOf("build"); System.out.println(start); return line.substring(start + "build".length()).replace(")", "").trim(); } else { return null; } } } return null; } }