objectser.java
来自「java2参考大全上的例子的源码和自己的理解.」· Java 代码 · 共 46 行
JAVA
46 行
package objectser;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.*;
class Student
implements Serializable {
int id;
String name;
int age;
String department;
public Student(int id, String name, int age,
String department) {
this.id = id;
this.name = name;
this.age = age;
this.department = department;
}
}
public class Objectser {
public static void main(String args[]) {
Student stu = new Student(981036, "Li Ming", 16, "CSD");
try {
FileOutputStream fo = new
FileOutputStream("date.ser");
ObjectOutputStream so = new
ObjectOutputStream(fo);
so.writeObject(stu);
so.close();
}
catch (Exception e) {
;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?