Here you can find the source of serialize(String filename, T obj)
Parameter | Description |
---|---|
T | a serializable type |
filename | the file to which the serialization is written |
obj | the serializable object |
Parameter | Description |
---|
public static <T> void serialize(String filename, T obj) throws FileNotFoundException, IOException
//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); } }