📄 example8_12.java
字号:
import java.io.*;
import java.util.*;
class ReadDat
{
FileInputStream file;
ObjectInputStream in;
public ReadDat()
{
try
{
file= new FileInputStream("test.dat");
in = new ObjectInputStream(file);
}
catch(IOException ioe)
{ System.out.println(ioe+"文件打开错误"); }
try
{
Date date = (Date)in.readObject();
Address address = (Address)in.readObject();
in.close();
System.out.println("Date: " + date );
System.out.println("Address: " + address);
}
catch(ClassNotFoundException e)
{ System.out.println(e+"对象错误"); }
catch(IOException ioe)
{ System.out.println(ioe+"读文件数据错误"); }
}
}
//主类
public class Example8_12
{
public static void main( String args[ ] )
{
new ReadDat();
}
}
class Address implements Serializable
{
protected String first, email;
public Address( )
{
first = email = "";
}
public Address( String _first, String _email )
{
first = _first;
email = _email;
}
public String toString( )
{
return first + " (" + email + ")" ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -