简体   繁体   English

JAR转换后从文件夹加载图像

[英]Image Loading From a Folder After JAR Conversion

In my project i have to load images stored in a folder in source folder. 在我的项目中,我必须加载存储在源文件夹中的文件夹中的图像。 But after i convert the project into jar it cant load any images.( I have selected the image(sticker) folder as resource when jar conversion and found many similar question in stackoverflow but they dont work for me).As i have to work in Intellij IDE so it will be good if you say for Intellij(14). 但是在我将项目转换为jar后,它无法加载任何图像。(当jar转换时,我选择了image(sticker)文件夹作为资源,并且在stackoverflow中发现了许多类似的问题,但它们对我不起作用)。因为我必须在Intellij IDE,所以如果您说Intellij(14)会很好。 Code for loading image 加载图片的代码

void load()
{
    sticker[0]="sticker\\bang.gif";
    sticker[1]="sticker\\birthday.gif";
    sticker[2]="sticker\\bye.gif";
    sticker[3]="sticker\\cry.gif";
    sticker[4]="sticker\\dance.gif";
    sticker[5]="sticker\\exercise.gif";
    sticker[6]="sticker\\headbang.gif";
    sticker[7]="sticker\\jail.gif";
    sticker[8]="sticker\\killing.gif";
    sticker[9]="sticker\\kiss.gif";
    sticker[10]="sticker\\laugh.gif";
    sticker[11]="sticker\\leftright.gif";
    sticker[12]="sticker\\light.gif";
    sticker[13]="sticker\\listening.gif"
}

projectStructure

You would want to use a class loader to load resources that are packaged in the jar itself. 您可能想使用类加载器来加载打包在jar本身中的资源。

public class FooClass {

    public void load(){

        InputStream sticker = FooClass.class.getClassLoader().getResourceAsStream("path/to/sticker.gif");

    }

}

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

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