3 Replies Latest reply: Dec 15, 2009 7:19 AM by 796085 RSS

    Can a Serialized Object be temporary?

    843790
      I have a simple swing application.

      I want to serialize an object, but have it temporary, so that if the client closes or dies, the serialized object automatically goes with it. Is this possible?

      Thanks,
      Richard
        • 1. Re: Can a Serialized Object be temporary?
          796085
          What does that even mean?

          Serialisation is the process of converting an object (graph) to a stream of bytes. If you put those bytes into a persistent store (file/database/etc.) then they are persistent. If you don't, then they aren't.
          • 2. Re: Can a Serialized Object be temporary?
            843790
            I'll try to explain.

            At present I serialize my object using:
                FileOutputStream fos = null;
                ObjectOutputStream out = null;
                
                fos = new FileOutputStream(saveFileName);
                out = new ObjectOutputStream(fos);
                out.writeObject(myResult);
                out.close();
            However, I want the file on disk to 'delete on exit' if my application is killed or closes. Like it would if I had done:
            File myFile = new File("xxxx");
                myFile.createTempFile("yyy","zzz");
                myFile.deleteOnExit();
            So, is it possible to serialize an object in this way?

            Thanks,
            Richard
            • 3. Re: Can a Serialized Object be temporary?
              796085
              This question is nothing at all to do with serialisation as far as I can make out.

              Why can't you just use
              new File(saveFileName).deleteOnExit();
              ?