Java ObjectOutputStream Write saveObject(String filename, Object obj)

Here you can find the source of saveObject(String filename, Object obj)

Description

save Object

License

Open Source License

Parameter

Parameter Description
filename a parameter
obj a parameter

Declaration

public static boolean saveObject(String filename, Object obj) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;

public class Main {
    /**//w  w  w. ja v a 2  s .  c  o m
     * 
     * @param filename
     * @param obj
     * @return
     */
    public static boolean saveObject(String filename, Object obj) {
        try {
            FileOutputStream fileOut = new FileOutputStream(filename);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(obj);
            out.close();
            fileOut.close();
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. saveObject(Object object, String filename)
  2. saveObject(Object object, String filename)
  3. saveObject(Object saveObject, File path)
  4. saveObject(Serializable obj, String url)
  5. saveObject(String filename, Object obj)
  6. saveObject(String filePath, Serializable obj)
  7. saveObject(T object, File file, boolean use_compression)
  8. saveObject2File(final Serializable object, final File file)
  9. saveObject2FileImpl(final Serializable object, final File file)