Java Object Save writeObjectToFile(Object obj, String path)

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

Description

write Object To File

License

Open Source License

Declaration

public static void writeObjectToFile(Object obj, String path) 

Method Source Code


//package com.java2s;
import java.io.File;

import java.io.FileOutputStream;

import java.io.ObjectOutputStream;
import java.io.OutputStream;

public class Main {

    public static void writeObjectToFile(Object obj, String path) {
        writeObjectToFile(obj, new File(path));
    }// w  w w  .j  a  v  a  2s  . c o  m

    public static void writeObjectToFile(Object obj, File path) {
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(path);
            writeObjectToFile(obj, out);
        } catch (Exception ex) {
        } finally {
            try {
                out.close();
            } catch (Exception ex) {
            }
        }
    }

    public static void writeObjectToFile(Object obj, OutputStream out) {
        ObjectOutputStream objOut = null;
        try {
            objOut = new ObjectOutputStream(out);
            objOut.writeObject(obj);
        } catch (Exception ex) {
        } finally {
            try {
                objOut.close();
            } catch (Exception ex) {
            }
        }
    }
}

Related

  1. writeObjectToFile(Object o, File file, boolean append)
  2. writeObjectToFile(Object o, String filename)
  3. writeObjectToFile(Object o, String fileName)
  4. writeObjectToFile(Object obj, File f)
  5. writeObjectToFile(Object obj, String fileName)
  6. writeObjectToFile(Object object, File file)
  7. writeObjectToFile(Object oObject, File destDir, String filename)
  8. writeObjectToFile(String dirname, String filename, Object obj)
  9. writeObjectToFile(String fileName, Object obj)