我需要通过 C# 获取 Java 路径的最佳方法。目前我正在这样做:
public String getJavaPath()
{
String javaKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment";
using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(javaKey))
{
String currentVersion = baseKey.GetValue("CurrentVersion").ToString();
using (var homeKey = baseKey.OpenSubKey(currentVersion))
return homeKey.GetValue("JavaHome").ToString();
}
}
但这并不适用于每台计算机。你们中有人知道获得路径的更好方法吗?