Here you can find the source of writeObjectToFile(T object, File fileHandle)
Parameter | Description |
---|---|
T | a parameter |
object | a parameter |
fileHandle | a parameter |
public static <T extends Object> boolean writeObjectToFile(T object, File fileHandle)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { /**// ww w . j a v a 2s . co m * Write a serializable object to a file * @param <T> * @param object * @param fileHandle * @return true if the file is written successfully */ public static <T extends Object> boolean writeObjectToFile(T object, File fileHandle) { try { FileOutputStream fos = new FileOutputStream(fileHandle); ObjectOutputStream output = new ObjectOutputStream(fos); output.writeObject(object); output.close(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return true; } }