Java ObjectOutputStream Write saveObjectToFile(File file, Object object)

Here you can find the source of saveObjectToFile(File file, Object object)

Description

save Object To File

License

LGPL

Declaration

public static boolean saveObjectToFile(File file, Object object) 

Method Source Code


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

import java.io.*;

public class Main {
    public static boolean saveObjectToFile(File file, Object object) {
        ObjectOutputStream os = null;
        try {//from   w  ww  .  j a v a  2s  .c o  m
            os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
            os.writeObject(object);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            safeClose(os);
        }

        return false;
    }

    public static void safeClose(Closeable os) {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. saveObject(String filePath, Serializable obj)
  2. saveObject(T object, File file, boolean use_compression)
  3. saveObject2File(final Serializable object, final File file)
  4. saveObject2FileImpl(final Serializable object, final File file)
  5. saveObjectInFile(String fileName, Object obj)
  6. saveObjectToFile(File thatFile, Object... thisObject)
  7. saveObjectToFile(final Object object, final String fileName)
  8. saveObjectToFile(Object obj, String fileName)
  9. saveObjectToPath(T objectToSave, String pathToSaveTo)