在jar中加载图像 [英] Loading images in a jar

查看:131
本文介绍了在jar中加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用eclipse,我使用以下代码从文件夹加载我的图像。

I am using eclipse and I use the following code to load my image from a folder.

getClass().getResource("/images/image.jpg").getFile())

图像文件夹位于里面项目文件夹中的bin文件夹。它在eclipse中加载时工作正常,但是当我将它导出到jar时它不会加载。我已经尝试将图像文件夹放在jar中的所有可能位置,但它没有。

The image folder is located inside the bin folder in the project folder. It works fine when loading in eclipse, but when I export it to a jar it does not load. I have tried puting the image folder in all possible places in the jar, but it does not.

如何在jar中加载图像文件夹?

How do I load an image folder in a jar?

推荐答案

您可以使用 getResourceAsStream()方法获取 InputStream 包含文件数据的实例。

You can use getResourceAsStream() method instead to get InputStream instance with your file data.

UPDATE :在jar的帮助下从jar中加载文件装载机。它可以为您提供任何内部资源的InputStream(不是FileInputStream)实例(无论是图像文件还是声音文件或文本文件)。文件写入不应该在jar内部工作。

UPDATE: Loading of files from a jar happens with the help of class loader. And it can give you instance of InputStream (not FileInputStream) of any internal resource (be it image file or sound file or text file). File writing shouldn't work inside jar.

这篇关于在jar中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆