public class Main{
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
try {
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle(0,
0,(int)dimension.getWidth(),(int)dimension.getHeight()));
String path = System.getProperty("user.dir") + "\\" + "images";
File file = new File(path);
if(!file.exists()){
file.mkdir();
}
file = new File(path+"\\"+"1.jpg");
ImageIO.write(screenshot, "jpg", file);
} catch (HeadlessException e) {
e.printStackTrace();
} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("截图成功");
}
}