I'm trying to load a PNG file into a BufferedImage like so:
BufferedImage image = ImageIO.read(new File("smile.png"));
When I use this line of code alone, it produes the error:
Unhandled Exception Type IOException...
I can fix this by surrounding the statement with try/catch like so:
BufferedImage image = null;
try
{
image = ImageIO.read(new File("smile.png"));
}
catch (IOException e)
{
System.out.println(e);
}
My question is, do you always have to handle IOExceptions when using ImageIO.read()? if so, then why and are there any other classes that do this? I've done a lot of research on the internet and couldn't find a definative answer.
Thanks :)