1
\$\begingroup\$

I have 3 files. A JSON file, a PNG file, and a TXT file. Is there any possible way I can put all three inside a common file with a custom extension? (for example "fileName.abc")

I searched the web a little, and found this which is perfect, and exactly what I need:
https://gist.github.com/MobiDevelop/5514357
Which is a zip solution. But I don't want to compress the files and if the extension is not zip, I would be happier.

Question 1: Can we change a file's extension ("file.png" to "file.abc") and read it as if it had the same extension?

Question 2: How can I put multiple files into same file, just like AAA games do?

Question 3: Can I just create a non-compressed zip file and change the extension? And read it using the class in the link?

Question 4: Is there a better way than question 3? Maybe a third party solution or something?

EDIT: I don't want the files to be compressed because the game will be runned on mobile devices too. And the game might be loading files during gameplay. I am just worried that there might be staggers, fps drops while loading files.

\$\endgroup\$
  • \$\begingroup\$ Could you add why you need this? The reason behind why you don't want them compressed is not clear.. \$\endgroup\$ – Vaillancourt Mar 25 '16 at 14:57
  • \$\begingroup\$ @AlexandreVaillancourt read my edit. Thanks for answering by the way. \$\endgroup\$ – ossobuko Mar 25 '16 at 15:47
  • 1
    \$\begingroup\$ Whether you bundle or not, compress or not, you'll have to read your data. I suggest you find your 'minimum requirements' device, and test with that; if you see the framerate drop because of the way you load your data, you should revise the way you do it. In any case, start with with what's the simplest to implement, and fix it only if there are issues. \$\endgroup\$ – Vaillancourt Mar 25 '16 at 15:54
  • \$\begingroup\$ Maybe I should test compressed and not compressed zip files and look at the time difference. \$\endgroup\$ – ossobuko Mar 25 '16 at 16:41
  • \$\begingroup\$ Yeah; start with compressed, if it works well, good, otherwise, try without compression. \$\endgroup\$ – Vaillancourt Mar 25 '16 at 16:59
1
\$\begingroup\$

Can we change a file's extension ("file.png" to "file.abc") and read it as if it had the same extension?

It depends on your framework. I don't know about libGDX, but some framework will open the file based on its extension, so renaming the file will not work. It's easily testable with a simple application.

How can I put multiple files into same file, just like AAA games do?

They usually use a custom file format, or a zip file or the like (rar, 7z, whatever they decide). I see two advantages into doing this like that: it reduces the total file size (if there is compression) and increase the read speed because there are more chances that the files needed are close one to another on the disk (I think Wii games needed to be like this).

Can I just create a non-compressed zip file and change the extension?

I know at least Quake3 did that. I'm not sure why you would like to have it not compressed, though (reading whole files from disk is usually slower than reading a much smaller archive into memory and decompressing from there).

And read it using the class in the link?

I don't know. You'll have to see for yourself (technology recommendation is off topic here).

Is there a better way than what I already suggested?

I think you have all the info now. Unless you have very specific needs, zipping the files together is usually enough for most needs.

\$\endgroup\$
0
\$\begingroup\$

Question 1: Can we change a file's extension ("file.png" to "file.abc") and read it as if it had the same extension?

Yes this is possible with LibGDX.

Question 2: How can I put multiple files into same file, just like AAA games do?

I ended up putting them inside a Zip file and changed the extension.

Question 3: Can I just create a non-compressed zip file and change the extension? And read it using the class in the link?

The given class in the link has a problem. When the zip file is inside a jar file, you cannot use random access. You have to create a stream everytime you want to access a file. This will set you in the right direction: https://stackoverflow.com/questions/23869228/how-to-read-file-from-zip-using-inputstream

Question 4: Is there a better way than question 3? Maybe a third party solution or something?

I wish there was. But I didn't find any.

Of course if you use zip files, anyone can open the jar and then the zip files with winrar, even if you change the .zip extension to something else.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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