This discussion is archived
6 Replies Latest reply: Apr 7, 2010 4:23 PM by EJP RSS

exception handling writeObject method

843790 Newbie
Currently Being Moderated

I serialize an object and write it to a file. I want to be sure that if an exception occurs at the method writeObject, i can surely delete the file I created.

          File file;
          ObjectOutputStream output;
          file = new File("test.ser");
          output = new ObjectOutputStream(new FileOutputStream(file));

          try {
          } catch (IOException e) {
               // to handle

Should I do something like that "file.deleteOnExit()" if file exists, or what else?