3 Replies Latest reply: May 17, 2010 8:47 AM by 843790 RSS

    not closing FileInputStream and FileOutputStream while seiralizing

    843790
      Hi,

      While using serialization as below

      In read step
      ObjectInputStream objstream = new ObjectInputStream(new FileInputStream(filename));
      Object object = objstream.readObject();
      objstream.close();
      and in write step
       
      ObjectOutputStream objstream = new ObjectOutputStream(new FileOutputStream(filename));
      objstream.writeObject(object);
      objstream.close();
      We do not close the FileInputStream and FileOutputStream. Is there a risk of doing so?

      Or should we define variables of their types, give these variables to ObjectInputStream and ObjectOutputStream, respectively, and then close them at the end of read and write operations..

      Thanks

      cenkbah