0

I'm currently working on a little game and I want to upload it when it's finished. But I have one problem. When I'm creating a refference to my Data with ImageIO.read I can only refference the specific path of the file. But if for example someone downloads it and puts it into another folder the code can't see the file anymore. Here is a visual representation of my problem:

static BufferedImage H;

static BufferedImage J;


public Boss() {

    try {

        H = ImageIO.read(new File("\\test\\Boss\\Hintergrund\\Hintergrund_01_B.jpeg"));

        J = ImageIO.read(new File("Hintergrund_01_B.jpeg"));


    }catch(IOException e) {

        e.printStackTrace();
        System.out.println("data not found");


    }

}

Here H can be read and J not. Why is that? Thanks for everyone who is willing to help me.

Connor
  • 1
  • 1
    Don't read the file as a file but rather as a resource that is included *within* the jar file. – Hovercraft Full Of Eels Aug 07 '18 at 23:18
  • The H version reads an absolute path name element. The J version reads the file relative to the current directory. You may output "(new File("Hintergrund_01_B.jpeg")).getAbsolutePath()" to check the searched file location. @HovercraftFullOfEels I do not see a reference to a JAR file within the question. – Konrad Aug 07 '18 at 23:36
  • thanks I found my problem. I was trying to Hard to search through all of my computer files to find the Data. But I only had to include that into my jar file as an extra source folder so I could export that file with my code. – Connor Aug 08 '18 at 00:51

0 Answers0