Java ObjectOutputStream Write saveObject(File file, Object o, boolean overwrite)

Here you can find the source of saveObject(File file, Object o, boolean overwrite)

Description

save Object

License

Apache License

Declaration

public static synchronized void saveObject(File file, Object o, boolean overwrite) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    public static synchronized void saveObject(File file, Object o, boolean overwrite) throws IOException {
        ObjectOutputStream oos = null;
        if (file.exists() && !overwrite) {
            throw new IOException("file exists: " + file.getCanonicalPath());
        }/*  w w  w .  j ava2  s .c  o m*/
        try {
            oos = new ObjectOutputStream(new FileOutputStream(file));
            oos.writeObject(o);
        } finally {
            if (oos != null) {
                oos.close();
            }
        }
    }
}

Related

  1. saveFile(Object o, File file)
  2. saveFile(Object o, String filename)
  3. saveGZipObject(Object toSave, File file)
  4. saveIndex(String path, Serializable obj)
  5. saveInSerFile(String filename, T object)
  6. saveObject(File file, Serializable obj)
  7. saveObject(Object o, File f)
  8. saveObject(Object obj, File file)
  9. saveObject(Object object, File file)