Here you can find the source of saveObject(Object object, File file)
Parameter | Description |
---|---|
object | The object to save. |
file | The file where the object will be stored. |
Parameter | Description |
---|---|
IOException | an exception |
public static void saveObject(Object object, File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { /**/*w w w. ja va 2 s . c o m*/ * Saves a raw Object to a file. * * @param object The object to save. * @param file The file where the object will be stored. * @throws IOException */ public static void saveObject(Object object, File file) throws IOException { if (!file.exists()) { file.getParentFile().mkdirs(); } final ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); oos.writeObject(object); oos.close(); } }