Re: jdk 1.5 question
thank you for you patience for non java programmer like me who is more of an
administrator then programmer nowadays..
I definitely should study more on serilazation. I read the article you gave
me. Thank you.
Before reading your article, I failed to find readobject as part of HashMap
or its ancestor. consequently, I took an example from google search to try
deserialize hashmap when the corresponsding object file is found for my
class in teh constructor .
Actually I am surprised that the compiler asked me for the serialVersionUID.
All Idid was added my custom classs of
package regextest;
/**
*
* @author g2
*/
public class RegexRecord {
String Name, Regex, Remark, Option, Groups;
Boolean bTested;
/** Creates a new instance of RegexRecord */
public RegexRecord() {
}
}
so I can declare in my RegexTest.java
HashMap<String, RegexRecord> myRegexHolder;
......
String myRegexHolder = strHomeFolder + ".RegeextTest_RegexHolder.ser"
and in the constructor to determine if I should create form scratch an empty
myRegexHolder or if the corresponding serilized object is found for teh
user, deserialize:
if ( (new java.io.File(strRegexHolderObjFSpec)).exists()) {
// restore myRegexHolder
boolean bFailed = false;
try {
// read and deserialize the blob
FileInputStream fileIn = new
FileInputStream(strRegexHolderObjFSpec);
ObjectInputStream inStream = new ObjectInputStream(fileIn);
myRegexHolder = (HashMap<String, regextest.RegexRecord>)
inStream.readObject();
} catch (ClassNotFoundException ex) {
setStatus("Exception in deSerializing myRegexHolder: " +
ex.getMessage());
ex.printStackTrace();
bFailed = true;
} catch (IOException ex) {
setStatus("Exception in deSerializing myRegexHolder - IO
error: " + ex.getMessage());
ex.printStackTrace();
bFailed = true;
}
I thought I was using the java.util.hashMap
but I guess I missused the javaio.inStream.readObject
.....\RegexTest\src\regextest\RegexTest.java:55: warning: [unchecked]
unchecked cast
found : java.lang.Object
required: java.util.HashMap<java.lang.String,regextest.RegexRecord>
myRegexHolder = (HashMap<String, regextest.RegexRecord>)
inStream.readObject();
1 warning
So do I have do?