![这里写代码片](https://img-blog.csdn.net/20180419150558282?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plbmdfbW91bW91/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
- 列表内容
- 我
- 三
- 我啊
- 列表内容
标题
2
public class ScreenShot {
public static void shoot(int x,int y,int w,int h){
Rectangle rect = new Rectangle(x, y, w, h);
String filename = "D:/dati";
Robot robot = null;
FileOutputStream fos = null;强调内容
try {
robot = new Robot();
} catch (Exception e) {**重点内容**
// TODO Auto-**generated catch block**
**e.printStackTrace();**
}
BufferedImage bi = robot.createScreenCapture(rect);
try {
File file = new File(filename + ".png");
fos = new FileOutputStream(file);
ImageIO.write(bi, "png", fos);
bi.flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(fos != null){
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
“`