我有一些命令可以在磁盘上创建文件。
由于文件夹是动态的,因此我有一个catch(FileNotFoundException e)。在同一个try块中,我已经有了一个catch(Exception e)块。
但是,当我运行代码并且文件夹尚不存在时,却使用了catch(Exception e)块,而不是FileNotFoundException块。
然而,调试器很清楚(至少对我来说),显示了一个FileNotFoundException:java.io.FileNotFoundException: c:\mydata\2F8890C2-13B9-4D65-987D-5F447FF0DDA7\filename.png(系统找不到指定的路径)。
有任何想法为什么它不进入FileNotFoundException块? 谢谢;
代码:
然而,调试器很清楚(至少对我来说),显示了一个FileNotFoundException:java.io.FileNotFoundException: c:\mydata\2F8890C2-13B9-4D65-987D-5F447FF0DDA7\filename.png(系统找不到指定的路径)。
有任何想法为什么它不进入FileNotFoundException块? 谢谢;
代码:
import java.io.FileNotFoundException;
try{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "png", new File(fileName));
}
catch (FileNotFoundException e){
// do stuff here..
return false;
}
catch(Exception e){
// do stuff here..
return = false;
}