As @Sergey K. said in his answer there are several ways to do this. One of these is using dxdiag
tool (obviously it will only work on Windows) particularly dxdiag /t
variant that will redirect the output to a given file. Then you can process that file to get required info:
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();
}
}
Generated file will look like this:
And output will look like this:
-- Executing dxdiag command --
-- Printing ./foo.txt info --
Card name: Intel(R) HD Graphics Family
Current Mode: 1366 x 768 (32 bit) (60Hz)