简体   繁体   English

从JAR内部访问png

[英]Accessing a png from inside a JAR

Currently I have a compiled JAR file as follows: 目前,我有一个编译的JAR文件,如下所示:

RunMe.jar  
-GUIFile.class  
-Main.class  
-Notify.class  
-resources  
--sprites  
---myimg.png  
-com  
--random  
---package  
----MakeNotify.class  

Please explain to me how to access the PNG myimg.png inside MakeNotify.java 请向我解释如何在MakeNotify.java访问PNG MakeNotify.java

Thanks for all the advice in advance. 感谢您提前提出的所有建议。

This depends, but generally, you want to use Class#getResource or Class#getResourceAsStream depending on how you want to read it. 这取决于,但是通常,您要根据要读取的方式使用Class#getResourceClass#getResourceAsStream

Something like... 就像是...

 BufferedImage img = ImageIO.read(getClass().getResource("/resources/sprites/myimg.png"));

for example... 例如...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM