这是我尝试从相对路径文件中获取图像的方法。
public static BufferedImage getInputImage(final String input) {
File file = new File("../" + input);
if (!file.exists() || !file.isFile()) return null;
BufferedImage image = null;
try {
image = ImageIO.read(new FileInputStream(file));
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
使用此功能,您可以输入:
res/img/green_tile.png
但它继续返回null,因为它认为该文件不存在。
感谢您的时间。