📄 studentdemo.java
字号:
import java.io.*;
class Student implements Serializable
{
int id;
String name;
int age;
String intro;
public Student(int id,String name,int age,String intro)
{
this.id=id;
this.name=name;
this.age=age;
this.intro=intro;
}
public String toString()
{
return "id=" + id + ";name=" + name + ";age=" + age+ ";intro=" + intro;
}
}
public class StudentDemo
{
public static void main(String args[]) throws IOException, ClassNotFoundException
{
Student stu=new Student(981036,"Liu Ming",18,"CSD");
System.out.println("Student:"+stu.toString());
FileOutputStream fo=new FileOutputStream("data.txt");
//keep the Object status;
ObjectOutputStream so=new ObjectOutputStream(fo);
try
{
so.writeObject(stu);
so.flush();
so.close();
}
catch(IOException e)
{
System.out.println(e);
}
FileInputStream fi=new FileInputStream("data.txt");
ObjectInputStream si=new ObjectInputStream(fi);
try
{
stu=(Student)si.readObject();
System.out.println("Student:"+stu.toString());
si.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -