Created
October 20, 2009 20:35
-
-
Save napsternxg/214595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
/** | |
* | |
* @author napsternxg | |
*/ | |
/* | |
All objects to be written must be instances of the class which either implements the Serializable or the Externalizable interface. | |
*/ | |
import java.io.*; | |
public class ObjectOperations { | |
FileInputStream fis; | |
FileOutputStream fos; | |
ObjectInputStream ois; | |
ObjectOutputStream oos; | |
public ObjectOperations(String fileName) { | |
// TODO Auto-generated constructor stub | |
try { | |
fos=new FileOutputStream(new File(fileName)); | |
oos=new ObjectOutputStream(fos); | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
try { | |
fis=new FileInputStream(new File(fileName)); | |
ois=new ObjectInputStream(fis); | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
public void writeObject(Object obj,String outputFile){ | |
try { | |
oos.writeObject(obj); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
public Object readObject(String inputFile){ | |
Object obj=new Object(); | |
try { | |
obj=ois.readObject(); | |
return obj; | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return obj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment