Java ImageIO:无法读取输入文件

时间:2011-11-24 02:39:15

标签: java file ubuntu javax.imageio

我不知道为什么这不起作用,但程序说它无法读取输入文件。顺便说一句,这也是在Ubuntu中运行的:

以下是示例代码:

URI url = new URI("images/GUI/TitleScreen.PNG");
File file = new File(url.toString());           
bg = new ImageBackground(ImageIO.read(file));

目录也位于程序的bin文件夹和src文件夹中。

1 个答案:

答案 0 :(得分:4)

如果您将图像作为资源中的流来获取,该怎么办?如,

String imgPath = "images/GUI/TitleScreen.PNG";
BufferedImage buffImage = ImageIO.read(getClass().getResourceAsStream(imgPath));
bg = new ImageBackground(buffImage);
相关问题