正如@Sergey K.在他的回答中所说,有几种方法可以做到这一点.其中一个是使用dxdiag工具(显然它只适用于Windows)特别dxdiag /t是将输出重定向到给定文件的变体.然后,您可以处理该文件以获取所需信息:
public static void main(String[] args) {
try {
String filePath = "./foo.txt";
// Use "dxdiag /t" variant to redirect output to a given file
ProcessBuilder pb = new ProcessBuilder("cmd.exe","/c","dxdiag","/t",filePath);
System.out.println("-- Executing dxdiag command --");
Process p = pb.start();
p.waitFor();
BufferedReader br = new BufferedReader(new FileReader(filePath));
String line;
System.out.println(String.format("-- Printing %1$1s info --",filePath));
while((line = br.readLine()) != null){
if(line.trim().startsWith("Card name:") || line.trim().startsWith("Current Mode:")){
System.out.println(line.trim());
}
}
} catch (IOException | InterruptedException ex) {
ex.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
生成的文件如下所示:

输出将如下所示:
- 执行dxdiag命令 -
- 打印./foo.txt信息 -
卡名:Intel(R)HD Graphics系列
当前模式:1366 x 768(32位)(60Hz)