Java Object Save writeObjectToFile(String fileName, Object obj)

Here you can find the source of writeObjectToFile(String fileName, Object obj)

Description

write Object To File

License

Apache License

Declaration

public static boolean writeObjectToFile(String fileName, Object obj) 

Method Source Code


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

import java.io.File;

import java.io.FileOutputStream;

import java.io.ObjectOutputStream;

public class Main {
    public static boolean writeObjectToFile(String fileName, Object obj) {
        try {/*w  w  w.j a  va 2  s .c  o  m*/
            File f = new File(fileName);
            f.setWritable(true);

            FileOutputStream fout = new FileOutputStream(f);
            ObjectOutputStream oo = new ObjectOutputStream(fout);
            oo.writeObject(obj);
            fout.close();
            return true;
        } catch (Exception ex) {
            return false;
        }
    }
}

Related

  1. writeObjectToFile(Object obj, String fileName)
  2. writeObjectToFile(Object obj, String path)
  3. writeObjectToFile(Object object, File file)
  4. writeObjectToFile(Object oObject, File destDir, String filename)
  5. writeObjectToFile(String dirname, String filename, Object obj)
  6. writeObjectToFile(String filename, Serializable s)
  7. writeObjectToFile(String filename, T object)
  8. writeObjectToFile(String outputFileName, Object toWrite, boolean append)
  9. writeObjectToFile(T object, File fileHandle)