gpt4 book ai didi

java - 如何从 Eclipse 项目中的 res 文件夹中获取文件?

转载 作者:行者123 更新时间:2023-11-30 07:59:03 24 4
gpt4 key购买 nike

我一直在尝试从项目中的 res 文件夹中获取一个文件,以便将其用作 BufferedImage,但无济于事。

Trying to get the file and use ImageIO to get a BufferedImage

This is the project so far - the image is under /res/img

运行我上面所做的操作会抛出 IllegalArgumentException (ImageIO.read(Unknown Source))。除非 getResourceAsStream 返回空值,否则不会发生这种情况,这意味着我无法从 res 文件夹中正确获取文件。总的来说,我对如何解决这个问题有点迷失。

感谢您的宝贵时间。

最佳答案

只需这样做:

return ImageIO.read(new FileInputStream(new File("res/img/SmallDagger.png")));

关于java - 如何从 Eclipse 项目中的 res 文件夹中获取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32213759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com