'why src/images path not found in exported jar file

I have images folder under src folder(src/images). when i run program in eclipse, the program runs good but when i export runnable jar file and try to run this, i see error. I write in below:

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

My program:

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();
    }

}
}

I think jar file not found images folder. when i unzip jar file, the images folder not found. How can i solve my problem? i am beginner in java sorry if my question is easy.



Solution 1:[1]

So you are doing this

"src/icon.png"

And forgot the package. So this is what I've tried

"src/myPackage/icon.png"

And it works.enter image description here

Solution 2:[2]

The problem might be with file path.

This is probably not the best solution but you can try using absolute path

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Janti Miles
Solution 2 smruti ranjan