Java ObjectOutputStream Write saveFile(Object o, String filename)

Here you can find the source of saveFile(Object o, String filename)

Description

save File

License

Apache License

Declaration

public static boolean saveFile(Object o, String filename) 

Method Source Code


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

import java.io.*;

public class Main {
    private static final String DATA_DIR = "data/";

    public static boolean saveFile(Object o, String filename) {

        FileOutputStream fos = null;
        ObjectOutputStream oos = null;
        boolean success = false;

        try {/*  ww w  . j a v  a 2s .co m*/
            fos = new FileOutputStream(DATA_DIR + filename);
            oos = new ObjectOutputStream(fos);
            oos.writeObject(o);
            success = true;
        } catch (IOException e) {
            e.printStackTrace();
            success = false;
        } finally {
            try {
                oos.close();
            } catch (IOException e) {
                e.printStackTrace();
                success = false;
            }
        }
        return success;
    }
}

Related

  1. saveCompressed(String filename, Object o)
  2. saveData(HashMap data, String filename)
  3. saveData(Object data, String filename)
  4. saveDate(String path, Object obj)
  5. saveFile(Object o, File file)
  6. saveGZipObject(Object toSave, File file)
  7. saveIndex(String path, Serializable obj)
  8. saveInSerFile(String filename, T object)
  9. saveObject(File file, Object o, boolean overwrite)