是否可以列出 Java 7 程序中已安装的所有 (官方) 软件包? 如果可以,我该怎么做?
查看 /usr/bin 就足够了吗或者我可能会错过一些包?
问候
答案1
我终于找到了
String [] extCmdArgs = new String[]{"dpkg-query", "-W", "-f=${Package} ${Version}\n"};
Process fetchInstalledPackagesProcess = Runtime.getRuntime().exec(extCmdArgs);
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(fetchInstalledPackagesProcess.getInputStream()));
String line;
while(true){
line = reader.readLine();
if (line == null)
break;
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
reader.close();
}