2 Star 0 Fork 0

BESTI.IS.JAVA2018/20165337

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
Example10_13.java 1.17 KB
Copy Edit Raw Blame History
yueyuan authored 7 years ago . shiyan1
import java.io.*;
public class Example10_13 {
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);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/BESTI-IS-JAVA-2018/20165337.git
git@gitee.com:BESTI-IS-JAVA-2018/20165337.git
BESTI-IS-JAVA-2018
20165337
20165337
master

Search