Here you can find the source of serialize(T t, String path)
Parameter | Description |
---|---|
T | type of object |
t | object |
path | path of the file |
Parameter | Description |
---|---|
IOException | when IO error |
public static <T> void serialize(T t, String path) throws IOException
//package com.java2s; //License from project: Mozilla Public License import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.zip.GZIPOutputStream; public class Main { /**/*from w w w . ja v a 2 s .c om*/ * Serialize object. * * @param <T> type of object * @param t object * @param path path of the file * @throws IOException when IO error */ public static <T> void serialize(T t, String path) throws IOException { serialize(t, new FileOutputStream(path)); } /** * Serialize object. * * @param <T> type of object * @param t object * @param out output stream * @throws IOException when IO error */ public static <T> void serialize(T t, OutputStream out) throws IOException { try (ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(out))) { oos.writeObject(t); } } }