?? student.java~7~
字號:
package Student;import java.io.*;public class Student implements java.io.Serializable{ int id; String name; int age; public Student(int id,String name,int age){ this.id=id; this.name=name; this.age=age; } private void writeObject(ObjectOutputStream out)throws IOException{ out.writeInt(id); out.writeInt(age); out.writeUTF(name); } private void readObject(ObjectInputStream in)throws IOException{ id=in.readInt(); age=in.readInt(); name=in.readUTF(); } // main public static void main(String a[])throws IOException,ClassNotFoundException{ Student stu=new Student(2,"zhang",25); FileOutputStream fout=new FileOutputStream("data.ser"); ObjectOutputStream sout=new ObjectOutputStream(fout); try{ sout.writeObject(stu); sout.close(); } catch(IOException e){ System.out.println(e.getMessage()); } //stu=null; FileInputStream fin=new FileInputStream("data.ser"); ObjectInputStream sin=new ObjectInputStream(fin); try{ sin.readObject(); sin.close(); } catch(IOException e){ System.out.println(e.getMessage()); } System.out.println("student.name="+stu.name); System.out.println("student.id="+stu.id); System.out.println("student.age="+stu.age); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -