我考虑过使用下面的代码,但是有没有更简洁的方法呢?
Process theProcess = Runtime.getRuntime().exec("java -d64 -version");
BufferedReader errStream = new BufferedReader(new InputStreamReader(theProcess.getErrorStream()));
System.out.println(errStream.readLine());
最佳答案
决定发布这个作为答案:
public static boolean supports64Bit() {
try {
final Process process = Runtime.getRuntime().exec("java -d64 -version");
try {
return process.waitFor() == 0;
} finally {
process.getInputStream().close();
process.getOutputStream().close();
process.getErrorStream().close();
}
} catch (IOException e) {
// log error here?!
return false;
}
}
关闭与进程关联的所有流是一种很好的做法,可以防止资源泄漏。
未测试。
关于java - 如果 jvm 支持 -d64 选项,如何从 java 代码进行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3415449/