五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

對象流的源碼

2020-04-04 12:34 作者:小垃圾kiki  | 我要投稿
package cn.jd.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;
/*
?* 對象流:
?* 1先寫出后讀取
?* 2讀取的順序和寫出保持一致
?* 3不是所有的對象都可以序列化Serializable
?*/
public class ObjectTest2 {
?? ?public static void main(String[] args) throws IOException, ClassNotFoundException {
?? ??? ?ByteArrayOutputStream? baos=new ByteArrayOutputStream();
?? ??? ?ObjectOutputStream oos=new ObjectOutputStream(new BufferedOutputStream(baos));
?? ??? ?oos.writeUTF("我太難了");
?? ??? ?oos.writeInt(18);
?? ??? ?oos.writeBoolean(false);
?? ??? ?//加入對象
?? ??? ?oos.writeObject("希望世界和平");
?? ??? ?oos.writeObject(new Date());
?? ??? ?Employee emp=new Employee("小二",400);
?? ??? ?oos.writeObject(emp);
?? ??? ?oos.flush();
?? ??? ?byte[]? datas=baos.toByteArray();? ?
?? ??? ?ObjectInputStream ois=new ObjectInputStream(new BufferedInputStream(new ByteArrayInputStream(datas)));
?? ??? ? String msg=ois.readUTF();
?? ??? ? int age=ois.readInt();
?? ??? ? boolean flag=ois.readBoolean();
?? ??? ? Object str=ois.readObject();
?? ??? ? Object date=ois.readObject();
?? ??? ? Object employee=ois.readObject();
?? ??? ? //接下來我們就將類型還原,這里我們必須加上類型轉(zhuǎn)換
?? ??? ? if(str instanceof String) {
?? ??? ??? ? String strObj=(String)str;
//?? ??? ??? ? System.out.println(strObj);
?? ??? ? }
?? ??? ? if(date instanceof Date) {
?? ??? ??? ? Date dateObj=(Date)date;
//?? ??? ??? ? System.out.println(dateObj);
?? ??? ? }
?? ??? ? if(employee instanceof Employee) {
?? ??? ??? ?Employee empObj=(Employee)employee;
//?? ??? ??? ? System.out.println(empObj.getName()+"-->"+empObj.getSalary());
?? ??? ? }
//?? ??? ? System.out.println(msg);
?? ??? ?
?? ??? ?
?? ??? ?
?? ??? ?
?? ?}
}
//寫了一個javabean類?? 后期用來封裝數(shù)據(jù)?? transient
class Employee? implements java.io.Serializable{
?? ?private transient String name;
?? ?private double? salary;
?? ?public Employee() {
?? ??? ?
?? ?}
?? ?public Employee(String name, double salary) {
?? ??? ?this.name = name;
?? ??? ?this.salary = salary;
?? ?}
?? ?public String getName() {
?? ??? ?return name;
?? ?}
?? ?public void setName(String name) {
?? ??? ?this.name = name;
?? ?}
?? ?public double getSalary() {
?? ??? ?return salary;
?? ?}
?? ?public void setSalary(double salary) {
?? ??? ?this.salary = salary;
?? ?}
?? ?
?? ?
}


對象流的源碼的評論 (共 條)

分享到微博請遵守國家法律
花莲市| 涟水县| 金川县| 美姑县| 霍州市| 望谟县| 淮安市| 濮阳县| 正定县| 扬州市| 珠海市| 灵山县| 中山市| 井研县| 宜州市| 县级市| 鲁山县| 临颍县| 庐江县| 凤凰县| 建阳市| 闽侯县| 常熟市| 崇州市| 女性| 名山县| 遂溪县| 巫山县| 兴隆县| 公主岭市| 怀安县| 彭山县| 慈溪市| 澎湖县| 乌拉特后旗| 行唐县| 武平县| 宣武区| 衡南县| 丰宁| 徐州市|