[英]IOException while changing from File to BufferedImage
Error: Unhandled exception type IOException. 错误:未处理的异常类型IOException。
File imgLoc = new File("player.png");
BufferedImage img = ImageIO.read(imgLoc);
How do I get a bufferedImage from a file location? 如何从文件位置获取bufferedImage?
The cause of your problem is best determined by examining a stacktrace for the exception. 通过检查异常的堆栈跟踪可以最好地确定问题的原因。
As a temporary measure, replace those two lines with the following: 作为临时措施,请使用以下内容替换这两行:
File imgLoc = new File("player.png");
BufferedImage img;
try {
img = ImageIO.read(imgLoc);
} catch (IOException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace();
throw ex;
}
to send some diagnostics to standard error. 发送一些诊断到标准错误。 Run the modified app and post the resulting output.
运行修改后的应用程序并发布结果输出。
Possible causes include: 可能的原因包括:
Does the file exist ? 该文件是否存在? Are you by chance reading from an unexpected directory ?
您是否偶然从一个意外的目录中读取?
Try File.exists() and/or File.canRead() 尝试File.exists()和/或File.canRead()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.