How do I read a binary file in C++ if I generate it in Java?

Your problem is that you are using ObjectOutputStream to write the data. This encodes the object graph in a Java-specific form intended to be read with ObjectInputStream. To make the data stream compatible with C++ you would need to do one of two things:

  1. Implement in C++ code that understands the output format produced by ObjectOutputStream -- i.e. re-implement in C++ what Java does in ObjectInputStream. This is NOT recommended.
  2. Write your data out from Java using a standard FileOutputStream, in a serialized format that you define, that then can be read by your C++ code. How you specify and implement this is up to you but can be very simple, depending on the complexity of your data.

Tags:

C++

Java