Two applications need to export and import a single file which needs to include data and images, best file type?

StackOverflow https://stackoverflow.com/questions/20827210

  •  22-09-2022
  •  | 
  •  

Question

I'm making two Java applications one to collect data, another to use it. The one collecting will be importing a file from the other which will include data and images and will be decrypted.

I'm unsure what filetype to use. So far all of the data is in XML and works great but I need the images and was hoping not to have to rely on giving all the images in a folder with a path reference.

Ideas?

Was it helpful?

Solution

well, I think that the best way is to create your own format (.myformat or .data). This file will be in fact a Zip file that contains your XML file and images. There is no perfect example writen in java as far as I know. However, here are some examples :
Not in java

  • The best example is, as @Bolo said, the odt format. Indeed, OpenOffice writes the doc in an xml file, and the images too. All that is wrapped in an odt file.
  • The .exe file is an other example. The C files and the resources are put in a single file. try to open it with 7-zip, you'll see.
  • The Skyrim plugins are .esp file that contain the dds, the scripts, the niffs (textures)...

In java

  • The minecraft texture packs are a zip file that contains a .mcmeta file (the infos) and the textures (.png)
  • Jar files are like exe.

OTHER TIPS

If both programs are in java you could also go with serialization, which is basically saving an object as a file (suffix will be .ser I think) and then being able to retrieve it. You should google it, even if it won't help right now it is quite good to know about it.

I'd suggest using JSON. Gson is a decent library.
You can embed images as byte arrays.

Save the serialized string in a file with a preferred extension, read it from the second application, de-serialize, and reconstruct images.

You can convert binary image data to text with Base64 encoding and this way you can embed your images in XML. [1]: http://en.wikipedia.org/wiki/Base64

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top