Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将图像从我的 .jar 复制到一个文件夹。我做的第一件事是:
InputStream stream = this.getClass().getResourceAsStream("/resources/images/i.gif"); if (stream == null) { System.out.println("ERROR!!!"); }
有了这个,流总是空的。在我的罐子里,我有一个文件夹“resources/images”,里面有一个图像“i.gif”。
从javadoc:
getResourceAsStream()如果没有找到同名的资源,则返回 InputStream 对象或 null
它找不到指定的资源。
请参阅javadoc,它说:getResourceAsStream(name)如果没有找到具有此名称的资源,则方法返回 InputStream 对象或 null。
getResourceAsStream(name)
所以getResourceAsStream(name)找不到资源/resources/images/i.gif,它返回null。
/resources/images/i.gif