-1

I just started a new Java Project and I'm working on Animations atm, my question now is how do I link my res source folder with the project so that I can read images via

img = ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));

from that folder? Normally I they can only be read when they are in the

4
  • Add the folder to the classpath or let your build process put the content into the jar(s).
    – Thomas
    Nov 10, 2014 at 14:37
  • how do I add this folder to my classpath?
    – user263980
    Nov 10, 2014 at 14:38
  • That depends on how you're starting the application. If you're using the command line, have a look here: stackoverflow.com/questions/9053146/…
    – Thomas
    Nov 10, 2014 at 14:39
  • I'm not running it from the command line but I found it now, THX nevertheless :D
    – user263980
    Nov 10, 2014 at 14:44

1 Answer 1

0

if we assume that your resource folder is called "resources":

Image image = Toolkit.getDefaultToolkit().createImage(yourclassName.class.getResource("/resources/..."));
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.