A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

This week I learnt IO Stream and actually, this course kind of difficulty for me. This is difficult is not the reason that I cannot understand the definition or the pression of these contents. There are too many new familiar expressions and I need more time to get them. And the most import thing I learnt is 3 Exceptions. The following are the details.
1.        NotSerializableException:
Location: java.io.NotSerializable extends ObjectStreamException extends IOException
Tip: A tip message: Another exception WriteAbortedException will be happened at the same time.
Reason:
When using ObjectOutputStream to save the object of a class that havn't extended Serializable Interface.
Solve method:
Make the class extend the Serializable Interface.
2.        EOFException
Location: java.io.EOFEception extends IOException
The reason why happened?
According to the API file, this Exception is throwed because arriving to the end of the File or Stream by accident.
The code throwed this exception:             while((stu = ois.readObject())!=null){}
Solve method:
The format of read object expression is incorrect and re-write it with write format.
(But after re-write the code, only able to read one line of the serialized data. Need more time to finish this trouble.)
3.        InvalidClassException
Location: java.io.InvalidClassException Extends ObjectStreamException Extends IOException
Reason:
Stream classdesc serialVersionUID had been changed due to member variable has been qualified by transient keyword in the source code in Object class. This cause the serialVersionUIDs are different between Stream classdesc and local class.
Steps:
1. Serialize data save to the txt file.
2. Deserialize the data.
3. Edit the code the Object class (such as Student class).
4. Deserialize the data.
Solve method:
method 1:(not perfect method) Serialize data save to the txt file again after step 3.
method 2: Add the serialVersionUID manually in the Object class.

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马