📄 serial.java
字号:
import java.io.*;
public class serial
{
public static void main(String ars[])
throws IOException,ClassNotFoundException
{
Student stu =new Student(19,"dd",60,"hx");
FileOutputStream tos=new FileOutputStream("met.txt");
ObjectOutputStream os=new ObjectOutputStream(tos);
try
{
os.writeObject(stu);
os.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
stu=null;
FileInputStream fi=new FileInputStream("met.txt");
ObjectInputStream si=new ObjectInputStream(fi);
try
{
stu=(Student)si.readObject();
si.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
System.out.println("ID is"+stu.id);
System.out.println("name is"+stu.name);
System.out.println("age is"+stu.age);
System.out.println("dep is"+stu.dep);
}
}
class Student implements Serializable
{
int id;
String name;
int age;
String dep;
public Student(int id,String name,int age,String dep)
{
this.id=id;
this.name=name;
this.age=age;
this.dep=dep;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -