0

我已将我的代码从一个方法(按钮按下操作)转移到一个新类。它的功能是捕获屏幕图像(很像打印屏幕)并将其保存在计算机的某个位置。(在这种情况下,驱动器 c)它显示以下错误消息:

java.io.FileNotFoundException: c:\z\1.jpg (系统找不到指定的路径)

public class printScreen{

    public static void main(String args[]) throws AWTException, IOException
    {
        Robot robot = new Robot();

        Dimension a = Toolkit.getDefaultToolkit().getScreenSize();

        Rectangle rect = new Rectangle(a);

        BufferedImage img = robot.createScreenCapture(rect);

        ImageIO.write(img, "jpg", new File("c:/z/1.jpg"));
        ImageIO.write(img, "bmp", new File("c:/z/2.bmp"));
        ImageIO.write(img, "png", new File("c:/z/3.png"));
    }
}

有什么想法吗?所有帮助将不胜感激!谢谢!

4

1 回答 1

0
File f = new File("c:/z/1.jpg")
f.createNewFile();
ImageIO.write(img, "jpg", f);
于 2013-12-11T17:05:22.437 回答