Java ObjectOutputStream Write saveObject(Serializable obj, String url)

Here you can find the source of saveObject(Serializable obj, String url)

Description

Saves an Serializable Object to the hard disk.

License

LGPL

Parameter

Parameter Description
obj the serializable object to be stored
url the path to be stored

Declaration

public static void saveObject(Serializable obj, String url) 

Method Source Code

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

import java.io.FileOutputStream;

import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Main {
    /**/*  w ww  .j  ava 2s.  com*/
     * Saves an Serializable Object to the hard disk.
     * 
     * @param obj
     *    the serializable object to be stored 
     * @param url
     *    the path to be stored
     */
    public static void saveObject(Serializable obj, String url) {
        try {

            FileOutputStream fOut = new FileOutputStream(url);
            ObjectOutputStream objOut = new ObjectOutputStream(fOut);
            objOut.writeObject(obj);

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }
}

Related

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