![我们可以列出 Java 7 程序中已安装的包吗?](https://linux22.com/image/1099093/%E6%88%91%E4%BB%AC%E5%8F%AF%E4%BB%A5%E5%88%97%E5%87%BA%20Java%207%20%E7%A8%8B%E5%BA%8F%E4%B8%AD%E5%B7%B2%E5%AE%89%E8%A3%85%E7%9A%84%E5%8C%85%E5%90%97%EF%BC%9F.png)
是否可以列出 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();
}