Java: Loading resources from the file system

后端 未结 5 453
臣服心动
臣服心动 2021-01-22 18:07

My Project Setup

I have the following project setup:

\\program.jar  
\\images\\logo.png

In my code, I reference th

5条回答
  •  自闭症患者
    2021-01-22 18:34

    What I would do, if possible, is package your images in with your Jar.

    That way you don't have to worry about where your Jar is launched from.

    You would then need to load images similar to the following:

    InputStream stream = this.getClass().getClassLoader().
                                         getResourceAsStream("/images/logo.png");
    

提交回复
热议问题