1 Replies - 568 Views - Last Post: 14 January 2013 - 05:33 PM Rate Topic: -----

#1 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Best way to store resources? (Eclipse)

Posted 14 January 2013 - 04:34 PM

Hey guys, I have a small question which I hope you can offer some advice on…

I've lately been getting into Java, and I've decided to make a basic game with it just to see how it goes. But one thing that I can't get my head around is this… how can I store my various image files within the program so I don't have to worry about file systems and images being all over the place?

To give an example:
In a VB.NET game I was making, I was able to load resources into a resources folder and at build time it would embed those resources into my program. Is there any way I can store resources in java like that, and if not, what's the best way to store resources so that no matter where the .jar is placed I can refer to those resources in the same way every time?

I might not be making much sense…

If you need further explanation, I'll explain!
Thanks for your time…

(I have seen forum posts similar to this but I'd prefer to get an explanation properly)

Is This A Good Question/Topic? 0
  • +

Replies To: Best way to store resources? (Eclipse)

#2 natecat   User is offline

  • D.I.C Head

Reputation: 57
  • View blog
  • Posts: 233
  • Joined: 19-December 11

Re: Best way to store resources? (Eclipse)

Posted 14 January 2013 - 05:33 PM

It is quite simple, you can either use the default ClassLoader's getResourceAsStream(), or, as I prefer to do it, simply just use this code:
Image img = Toolkit.getDefaultToolkit().getImage(MyClass.class.getResource("image.jpg"));

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1