⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serialize.java~3~

📁 提供了常用的JAVA技术的示例
💻 JAVA~3~
字号:
package Student;import java.io.*;public class Serialize implements java.io.Serializable{    int id;    String name;    int age;    public Serialize(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{        Serialize stu=new Serialize(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{            stu=(Serialize)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 + -