Q:

Relative path's to images and sound in Java

Currently the project that I am making is game made with Jframe/Jpanel. I am using imports of images and sound through:
images:
    ImageIcon a = new ImageIcon("C:/Users/Home/IdeaProjects/Game/src/DragonRoll/sprites/user_sprite_down.png");
    player = a.getImage();
    //sign

Sound:
    String gongFile = ("C:/Users/Home/IdeaProjects/Game/src/DragonRoll/music/game_track.wav");
    InputStream in = new FileInputStream(gongFile);
    AudioStream audioStream = new AudioStream(in);
    AudioPlayer.player.start(audioStream);

The images and the soundtrack from the example is seen to be imported from a direct path not a relative one meaning that it does not work on other computer or devices since they do not have the exact same path. Can someone recommend any solutions to this, please provide example code. I have tried just removing the path except the folder which contains the images and the image name itself but that did not work.
I am using Intellij and running as an executable java file.
Also the folder which contains all of the project goes like:
- Main project folder
- Branches into .idea, out and src
- src contains classes of the game and 2 folders called images and music

A:

By convention source files in a Java project (everything that ends with .java) should be in a folder called src/main/java. Resources such as images, audio files, default config files, etc. are usually placed in a second source folder called src/main/resources. This way the compiled sources (i.e. the .class files) and the resource files will be on the classpath at run time of your application.
To load for example the src/main/resources/DragonRole/music/game_track.wav resource from your classpath you can simply do this:
InputStream gameTrackIn = MyClass.class.getResourceAsStream(
     "/DragonRole/music/game_track.wav");

To load the src/main/resources/DragonRoll/sprites/user_sprite_down.png resource from your classpath you can simply do this:
ImageIcon userSpriteDownImg = new ImageIcon(MyClass.class.getResource(
     "/DragonRoll/sprites/user_sprite_down.png"));

Your project structure should look like this:
Game (project root)
  └ src/main
     ├ java (source root)
     └ resources (resource root)

