Code example for ObjectInputStream

Methods: close, readObject

0
 
public class OOSSerializer implements ObjectSerializer { 
 
	public Object readObject(File f) throws IOException {
		try { 
			ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
			Object o = ois.readObject();
			ois.close();
 
			return o;
		} 
		catch (ClassNotFoundException e) {
			return null; 
		} 
	} 
 
	public void writeObject(File f, Serializable o, boolean force) throws IOException {
		FileOutputStream fos = new FileOutputStream(f);
		fos.getChannel().force(force);
 
		ObjectOutputStream oos = new ObjectOutputStream(fos);