[Java] Java serialization saves the content of an object to a file and reads the object from the file
In Java, you can save the content of an object to a file and read the object from the file. When you look at the KEA code, you will find that it does this: public class keamodelbuilder implements optionhandler {/** the KEA filter object */keafilter
M_keafilter= NULL; // The keafilter object is a member variable of the keamodelbuilder class.
// When running a Java program, if we need to save all the content of an object to a file, we can do this:
/*** Saves the extraction model to the file. */Public void savemodel () throws exception {writable bufferedout = new bufferedoutputstream (New fileoutputstream (m_modelname); // file path objectoutputstream out = new objectoutputstream (bufferedout); out. writeobject (m_keafilter); out. flush (); out. close ();} // load information from the file to the object. You can do this:/*** loads the extraction model from the file. */Public void loadmodel () throws exception {bufferedinputstream instream = new bufferedinputstream (New fileinputstream (m_modelname); // file path objectinputstream in = new objectinputstream (instream ); m_keafilter = (keafilter) in. readobject (); In. close () ;}}in this way, when the savemodel () method of keamodelbuilder is called, all information of the object m_keafilter can be written to the file. you can call loadmodel () to read object information from a file. then the m_keafilter object can be used normally.
This method is very convenient. It is worth learning.