Java 为什么在导出的jar文件中找不到src/images路径

Java 为什么在导出的jar文件中找不到src/images路径,java,image,jar,Java,Image,Jar,我在src文件夹(src/images)下有一个images文件夹。当我在eclipse中运行程序时,程序运行良好,但当我导出runnable jar文件并尝试运行它时,我看到了错误。我写在下面: java.io.FileNotFoundException: src\images\test2.bmp (The system cannot find the path specified) 我的节目: public class FirstSWTExample { public static voi

我在src文件夹(src/images)下有一个images文件夹。当我在eclipse中运行程序时,程序运行良好,但当我导出runnable jar文件并尝试运行它时,我看到了错误。我写在下面:

java.io.FileNotFoundException: src\images\test2.bmp (The system cannot find the
path specified)
我的节目:

public class FirstSWTExample {
public static void main(String[] args) {
  .
  .
  saveImage();
  Image image=new Image(display, "src/images/test2.bmp");
    shell.setImage(image);
  }
public static void saveImage() {
    String s="....";
    byte[] dataCustImg = Base64.decode(s.getBytes());

    try {

        OutputStream stream = new FileOutputStream("src/images/test2.bmp");

        stream.write(dataCustImg);
        stream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
}

我想jar文件找不到图像文件夹。当我解压缩jar文件时,找不到images文件夹。我怎样才能解决我的问题?我是java初学者,如果我的问题很简单,我很抱歉

问题可能在于文件路径

这可能不是最好的解决方案,但您可以尝试使用绝对路径

"C:\\projectName\\src\\images\\test2.bmp"

你在尝试这个吗?
ImageIO.read(getClass().getResource(“/images/test2.bmp”)Thnaks。但如何将其设置为我的外壳?我是Java新手当您在eclipse中运行程序时,有一个相对目录
src
,您的程序使用它。如果你想使用jar资源,你必须加载为
getClass().getResource(PATH)
,但是你可以改变它,看这个:谢谢。我编写URL imgPath=FirstSWTExample.class.getClassLoader().getResource(“/images/test2.bmp”);但是imgPath是空的。为什么?你的图像是内部的还是外部的?如果是在外面,你必须考虑SMRUTI RANJAN AWNSRY谢谢,但是我想在任何计算机上运行这个程序,也许一些计算机没有C驱动,然后你必须用你的罐子递送你的图像文件夹。