Here you can find the source of saveObject(Object object, String filename)
Parameter | Description |
---|---|
object | a parameter |
filename | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void saveObject(Object object, String filename) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; public class Main { /**/*from w w w . ja v a 2 s . c o m*/ * Stores a Serializable Object. * * @param object * @param out * * @throws IOException */ public static void saveObject(Object object, OutputStream out) throws IOException { if (!(object instanceof Serializable)) throw new IllegalArgumentException("The object is not Serializable!"); new ObjectOutputStream(out).writeObject(object); } /** * Stores a Serializable Object. * * @param object * @param filename * * @throws IOException */ public static void saveObject(Object object, String filename) throws IOException { saveObject(object, new FileOutputStream(filename)); } /** * Stores a Serializable Object. * * @param object * @param file * * @throws IOException */ public static void saveObject(Object object, File file) throws IOException { saveObject(object, new FileOutputStream(file)); } }