Java Object Save writeObjectToFile(Object obj, File f)

Here you can find the source of writeObjectToFile(Object obj, File f)

Description

Writes a generic object to a file

License

Open Source License

Declaration

public static boolean writeObjectToFile(Object obj, File f) 

Method Source Code

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

import java.io.File;

import java.io.FileOutputStream;

import java.io.ObjectOutputStream;

public class Main {
    /**/*from  w w w  .  j av a2  s.  co m*/
     * Writes a generic object to a file
     */
    public static boolean writeObjectToFile(Object obj, File f) {
        try {
            FileOutputStream fout = new FileOutputStream(f);
            ObjectOutputStream oos = new ObjectOutputStream(fout);
            oos.writeObject(obj);
            oos.close();
        } catch (Exception e) {
            System.out.println("Error writing Object to file: " + e.getMessage());
            return false;
        }
        return true;
    }
}

Related

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