s-day10--反序列化流读取对象(ObjectInputStream)
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
package com.inmind.xlh03;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/*
|
||||||
|
15.反序列化流读取对象(ObjectInputStream)
|
||||||
|
构造方法:
|
||||||
|
ObjectInputStream(InputStream in) 创建从指定的InputStream读取的ObjectInputStream。
|
||||||
|
|
||||||
|
常用方法:
|
||||||
|
Object readObject() 从ObjectInputStream读取一个对象。
|
||||||
|
|
||||||
|
*/
|
||||||
|
public class Demo09 {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
//使用反序列化流,读取对象
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("student.txt"));
|
||||||
|
Object o = ois.readObject();//多态
|
||||||
|
if (o instanceof Student) {
|
||||||
|
Student s = (Student) o;
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user