Here you can find the source of readObjectFromFile(String filename)
Parameter | Description |
---|---|
filename | the file to read from |
public static Object readObjectFromFile(String filename)
//package com.java2s; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInput; import java.io.ObjectInputStream; public class Main { /**/*from ww w . j av a2 s. c o m*/ * Read a serialized object from a file * @param filename the file to read from * @return the object read from the file or null if an error occurred */ public static Object readObjectFromFile(String filename) { //deserialize the the file try { //use buffering InputStream file = new FileInputStream(filename); InputStream buffer = new BufferedInputStream(file); ObjectInput input = new ObjectInputStream(buffer); try { //display its data return input.readObject(); } finally { input.close(); } } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return null; } }