0

How do I write to a pre-specified binary file format in Java that I can share with another computer that will parse it (and other computer is not using Java)? The file format has longs, floats, and some bitfields. This is a file that the Java program will write data to and then share with another computer. Is there a better way to do this than with a binary file format?

4
  • 1
    So you want something precompiled and written in java but running on a computer that doesn't have java?
    – SuperTron
    Dec 18, 2011 at 4:17
  • 1
    There are some ahead-of-time compilers for Java. Don't know whether any of them are any good or still maintained.
    – Gravity
    Dec 18, 2011 at 4:27
  • Are you trying to make a Java executable or a data file that is binary data instead of ASCII characters? Dec 18, 2011 at 4:40
  • 1
    he is trying to find a binary file format which can be written by Java and then parsed w/o Java (so to say using Java serialization is not a good fit for him)
    – MK.
    Dec 18, 2011 at 4:41

2 Answers 2

3

If it doesn't have to be binary you can use XML or JSON. If it has to be binary, use Protocol Buffers.

2
  • Yes, Protocol Buffers may work, but will I have to use the Protocol Buffer API to read the file too? I have pre-existing code written in PHP that parses my specific file format. It would be nice if I didn't have to rewrite any of that code. Dec 18, 2011 at 4:57
  • Protocol buffers have apis for everything. Re 2nd part of your comment -- please consider writing better questions, nobody wants to beg you to disclose enough information about your question so that we can help you.
    – MK.
    Dec 18, 2011 at 5:08
0

If it has to be binary, I would use ByteBuffer which support reading/write primitive in any combination and with any byte order (endianess) You can create wrappers so when you read/write it can appear as events, messages or event types (so you hide the fact you are dealing with a binary file)

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.