Here you can find the source of writeObjectToFile(Object o, File file, boolean append)
Parameter | Description |
---|---|
o | object to be written to file |
file | The temp File |
append | If true, append to this file instead of overwriting it |
Parameter | Description |
---|---|
IOException | If File cannot be written |
public static File writeObjectToFile(Object o, File file, boolean append) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.zip.GZIPOutputStream; public class Main { /**/*from ww w . j a va 2s . co m*/ * Write object to a file with the specified name. * * @param o * object to be written to file * @param filename * name of the temp file * @throws IOException * If can't write file. * @return File containing the object */ public static File writeObjectToFile(Object o, String filename) throws IOException { return writeObjectToFile(o, new File(filename)); } /** * Write an object to a specified File. * * @param o * object to be written to file * @param file * The temp File * @throws IOException * If File cannot be written * @return File containing the object */ public static File writeObjectToFile(Object o, File file) throws IOException { return writeObjectToFile(o, file, false); } /** * Write an object to a specified File. * * @param o * object to be written to file * @param file * The temp File * @param append If true, append to this file instead of overwriting it * @throws IOException * If File cannot be written * @return File containing the object */ public static File writeObjectToFile(Object o, File file, boolean append) throws IOException { // file.createNewFile(); // cdm may 2005: does nothing needed ObjectOutputStream oos = new ObjectOutputStream( new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file, append)))); oos.writeObject(o); oos.close(); return file; } }