import java.io.*;class Students implements Serializable{String name=null;double grade;Students(String name,double grade){this.name=name;this.grade=grade;}public void setGrade(double grade){this.grade=grade;}public void setName(String name){this.name=name;}public double getGrade(){return grade;} public String getName(){return name;} }public class likecool{public static void main(String[] args) {Students Stu1[]={new Students("小明",100),new Students("小红",0)};try{ ByteArrayOutputStream out= new ByteArrayOutputStream();ObjectOutputStream objectOut=new ObjectOutputStream(out);objectOut.writeObject(Stu1[]);//就是这一行提示需要.classByteArrayInputStream in=new ByteArrayInputStream(out.toByteArry());ObjectInputStream objectIn=new ObjectInputStream(in);Students Stu2[]=objectIn.readObject();System.out.println("学生的姓名和成绩:");for (int i=0;i<Stu2.length;i++)System.out.println(Stu2[i].getName(),Stu2.getGrade());}catch(Exception event){System.out.print(event);}}}
添加回答
举报
0/150
提交
取消