我需要它运行而不将文件导出到计算机.
目前,我存储图像的代码是:
ImageIcon icon = new ImageIcon("images\\images2.gif");
Run Code Online (Sandbox Code Playgroud)
它不仅仅是一个图像,因为我将它添加到JLabel.
当我对整个程序进行jar时,它会将图像文件存储在jar中.
当我去运行实际问题时,没有图像.
同样,我不能将.jar留在已包含图像的文件夹中.它必须单独在一台独立的计算机上工作.
Ste*_*Kuo 10
您将希望通过系统类加载器获取图像:
URL url = ClassLoader.getSystemClassLoader().getResource("images/images2.gif");
Icon icon = new ImageIcon(url)
Run Code Online (Sandbox Code Playgroud)
images 位于类路径的根部.
请注意,Java运行时会将separator(/)转换为特定于操作系统的分隔符(\对于Windows).
| 归档时间: |
|
| 查看次数: |
1173 次 |
| 最近记录: |