2 Replies Latest reply: Oct 12, 2007 6:00 AM by 791266 RSS

    exception in file reading

    807605
      I am writing some objects to a file using ObjectOutputStream. Initially some objects are written and then the output stream is closed. Then stream is opened and some more objects are written. This is done multiple times. Now while reading those objects with ObjectInputStream ( in a separate program ), I can only read those objects written ( before closing the output stream for the first time ) and not the remaining ones. I get the following exception

      - java.io.StreamCorruptedException: invalid type code: AC

      Please tell me what is the reason.

      Thanks.
        • 1. Re: exception in file reading
          800322
          I assume the reason is that you can't really append to such a file of serialized objects because you'd insert a set of header information where none is expected.
          • 2. Re: exception in file reading
            791266
            A header is written to the stream when an ObjectOutputStream is created. The stream is corrupt because your file has that header followed by some objects, and then another header.

            You need to subclass ObjectOutputStream and make sure that it only writes that header once (i.e implement append mode)

            Kaj