To take a screenshot in Java you can use the following snippet.

Sample Java

BufferedImage bufferedImage = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(bufferedImage, "png", new File("C:\screenshot.png"));

for more informations see BufferedImage, ImageIO, Toolkit: getScreenSize(), Robot


One thought on “How to take a screenshot in Java”

Leave a Reply