I've seen so many different posts about what way you're supposed to serialize an object to a file, and all of them conflict in nature on how to do it and what the best practices are. So here's what I'm trying to save:
public class IHandler{
public double currentLoad;
public String currentPrice;
public String configArgs[];
};
We can assume that the size of configArgs is known that I need to make a file, here's what I have so far.
public static void serializeDataOut(IHandler ISH)throws IOException{
String fileName= "Test.txt";
FileOutputStream fos = new FileOutputStream(fileName);
//What do I do here?
}
public static IHandler serializeDataIn(){
//What do I do here?
}
Well I assume, you want to write object directly into the file
I just provided important code. Implement this with exception handling.
You can use the XMLDecoder/XMLEncoder to serialize JavaBean as xml. Here are the examples from oracle's Javadocs on the two classes:
(XMLDecoder)
(XMLEncoder)
Note that you would need to add getters and setters and make the class serializable.
An example of how to serialize an object:
For more info http://docs.oracle.com/javase/tutorial/jndi/objects/serial.html
do you want to write IHandler into test.txt file? try
if you want read IHandler from that file, need do this