Java Object Serialize serialize(String filename, T obj)

Here you can find the source of serialize(String filename, T obj)

Description

Serialize an object to file.

License

Open Source License

Parameter

Parameter Description
T a serializable type
filename the file to which the serialization is written
obj the serializable object

Exception

Parameter Description

Declaration

public static <T> void serialize(String filename, T obj) throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
/*//from w  w w .  ja  va 2s  .c o  m
 * Copyright (C) 2015 Dieter J Kybelksties
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * @date: 2015-12-16
 * @author: Dieter J Kybelksties
 */

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectOutputStream;

public class Main {
    /**
     * Serialize an object to file.
     *
     * @param <T>      a serializable type
     * @param filename the file to which the serialization is written
     * @param obj      the serializable object
     * @throws java.io.FileNotFoundException
     */
    public static <T> void serialize(String filename, T obj) throws FileNotFoundException, IOException {
        FileOutputStream fileOut = new FileOutputStream(filename);
        ObjectOutputStream out = new ObjectOutputStream(fileOut);
        out.writeObject(obj);

    }
}

Related

  1. serialize(Serializable object, File dest)
  2. serialize(Serializable object, String fileName)
  3. serialize(Serializable s, File dir, String fileName)
  4. serialize(Serializable serializable)
  5. serialize(Serializable... objects)
  6. serialize(String path, String name, Object obj)
  7. serialize(T obj)
  8. serialize(T obj)
  9. serialize(T object)