【问题标题】:How do I go about getting a file from my res folder within my project in eclipse?如何从 Eclipse 项目中的 res 文件夹中获取文件?
【发布时间】:2015-11-19 17:36:19
【问题描述】:

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

运行我上面所做的会引发 IllegalArgumentException (ImageIO.read(Unknown Source))。 这不应该发生,除非 getResourceAsStream 返回一个空值,这意味着我没有从我的 res 文件夹中正确获取文件。 所以总的来说,我对如何解决这个问题有点迷茫。

感谢您的宝贵时间。

【问题讨论】:

    标签: java eclipse image file directory


    【解决方案1】:

    这样做:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 1970-01-01
      • 2014-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多