Merge an image file and a text file into one file

Hey guys!

Being a noob, I’m currently experiencing around with Slick and I’m trying to make little games.

I load sprite sheets and then read their properties (to construct collision shapes) from text files.
Those files contains only one line, which looks like this: ; ; .

I was wondering if I could combine the (regular) text file with the (png) image file into one file?

The new file would look like this: the first x bytes are reserved for the text data, followed by the image data. The read method would separate it when reading the file.

I’d like to make some reusable classes (mini engine?), so please forgive me if its a silly idea. ::slight_smile:

The easiest way to do this is to put in to a jar that is on the classpath. The use the getResource method in Class. A jar is just a zip archive. How good is that? well that is what quake3 even uses for its pak files.

There is a trick to doing this however. I put the class RootClassResourceFolder in my resource folder. This class does nothing but provide a way to use relative paths in the getResource method.

URL url =RootClassResourceFolder.class.getResource(s);

Anything else is more work than its worth IMO.

I havn’t looked at Slick, but I would presume that the images are in png format (considering php is kickass).

For the file it would be simple to just read a String and then just read the remainder bytes into a byte array and convert that to the image.

You could accomplish this pretty easily by using RandomAccessFiles (I would suggest FileChannels, however java 7 isn’t as widespread as I would want to make that a requirement to play).