1

To make my question more specific:

mapFile = new File("D:/Documents/Graphics/map.png");

     map = ImageIO.read(mapFile);

'map' is a BufferedImage I wish to put read image into. I have to use a bit uncomfortable directory format, an URL leading simply to project's src folder would be most welcomed (path would be "map.png" only). I do have a simple method that uses URL's and it's using something like this to get image adress:

java.net.URL imgURL = SpineMain.class.getResource("map.png");

but that beauty does not meet File's expectations (String). Is there any relatively simple way to change it?

[Btw - what I want to achieve is easily packable and movable folder with classes and essential files alike. Could any of you provide me with some clue how to start messing with exe files, it's subfolders with content files and so on? I know this does have little in common with my original question and is maybe too general, but I would be most grateful. Thanks for taking your time helping :) ]

1 Answer 1

2

Straightforward method: move your 'Graphics' folder into the one containing your main program, and add "Graphics/" before the image name in your getResource function.

Usually, a path that does not start with a drive and/or (back)slash, is considered being offset by your current path; so just "Graphics/map.png" ought to be enough to locate it.

This depends on what Java engines consider "the current working directory"; it should be the one your jar file is executing from. If so, you can use it as a fixed point in the path specification, and tag on any sub-folder names at will.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.