代码拉取完成,页面将自动刷新
import java.io.*;
public class E1013{
public static void main(String args []){
TV changhong=new TV();
changhong.setName("长虹电视");
changhong.setPrice(5678);
File file=new File("television.txt");
try{
FileOutputStream fileOut=new FileOutputStream(file);
ObjectOutputStream objectOut=new ObjectOutputStream(fileOut);
objectOut.writeObject(changhong);
objectOut.close();
FileInputStream fileIn=new FileInputStream(file);
ObjectInputStream objectIn=new ObjectInputStream(fileIn);
TV xinfei=(TV)objectIn.readObject();
objectIn.close();
xinfei.setName("新飞电视");
xinfei.setPrice(6666);
System.out.println("changhong的名字:"+changhong.getName());
System.out.println("changhong的价格:"+changhong.getPrice());
System.out.println("xinfei的名字:"+xinfei.getName());
System.out.println("xinfei的价格:"+xinfei.getPrice());
}
catch(ClassNotFoundException event){
System.out.println("不能读出对象");
}
catch(IOException event){
System.out.println(event);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。