Java????????л??????л?
???????????? ???????[ 2016/2/26 10:28:34 ] ??????????????? ???????????
????Externalizable???
????????Serializable ???java?л?????????????л????Externalizable
??????????Externalizable????Serializable????????????????????????????????????Externalizable???????
package com.hollischaung.serialization.ExternalizableDemos;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
/**
* Created by hollis on 16/2/17.
* ???Externalizable???
*/
public class User1 implements Externalizable {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void writeExternal(ObjectOutput out) throws IOException {
}
public void readExternal(ObjectInput in) throws IOException?? ClassNotFoundException {
}
@Override
public String toString() {
return "User{" +
"name='" + name + ''' +
"?? age=" + age +
'}';
}
}
package com.hollischaung.serialization.ExternalizableDemos;
import java.io.*;
/**
* Created by hollis on 16/2/17.
*/
public class ExternalizableDemo1 {
//????????????????????????????????????????????????????????????
//IOException??????
public static void main(String[] args) throws IOException?? ClassNotFoundException {
//Write Obj to file
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("tempFile"));
User1 user = new User1();
user.setName("hollis");
user.setAge(23);
oos.writeObject(user);
//Read Obj from file
File file = new File("tempFile");
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
User1 newInstance = (User1) ois.readObject();
//output
System.out.println(newInstance);
}
}
//OutPut:
//User{name='null'?? age=0}
?????????????????????????User1????????л????????л???????????????????????????????????????????????????????????б???????????????Externalizable????Serializable????????
????Externalizable?????Serializable???y???ж?????????????????writeExternal()??readExternal()???????Externalizable????????????л??????л??????????????????дwriteExternal()??readExternal()???????????????????У???????????????????ж??????л???????????????????????????????????????????Externalizable???????л??????????????????????????л??????ι??????????????μ??????????????????????ε??????????????С?????????Externalizable???????????????public????ε????????
???????????????????????£?
package com.hollischaung.serialization.ExternalizableDemos;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
/**
* Created by hollis on 16/2/17.
* ???Externalizable?????????writeExternal??readExternal????
*/
public class User2 implements Externalizable {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(name);
out.writeInt(age);
}
public void readExternal(ObjectInput in) throws IOException?? ClassNotFoundException {
name = (String) in.readObject();
age = in.readInt();
}
@Override
public String toString() {
return "User{" +
"name='" + name + ''' +
"?? age=" + age +
'}';
}
}
package com.hollischaung.serialization.ExternalizableDemos;
import java.io.*;
/**
* Created by hollis on 16/2/17.
*/
public class ExternalizableDemo2 {
//????????????????????????????????????????????????????????????
//IOException??????
public static void main(String[] args) throws IOException?? ClassNotFoundException {
//Write Obj to file
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("tempFile"));
User2 user = new User2();
user.setName("hollis");
user.setAge(23);
oos.writeObject(user);
//Read Obj from file
File file = new File("tempFile");
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
User2 newInstance = (User2) ois.readObject();
//output
System.out.println(newInstance);
}
}
//OutPut:
//User{name='hollis'?? age=23}
??????Σ??????????????????????????
???????User?????????????????????????????????????java.io.InvalidClassException
????????Externalizable???????????ο????????
????ObjectOutput??ObjectInput ???
????ObjectInput??? ????? DataInput ????????????????????
????DataInput ????????????????ж???????????????? Java ?????????????????????????????? UTF-8 ??????????????? String ??????
????????????е?????????????????????????????????????????????????β (end of file)??????? EOFException??IOException ??????????????????????β??????????????????????????? IOException ?????? EOFException??????????????????????????£?????? IOException??
????ObjectOutput ??? DataOutput ?????????????д???????
????DataOutput ????????????????? Java ??????????????????????????Щ???д???????????????????????? String ????? UTF-8 ????????д????????????????????
?????????????д?????????з?????????????????????д?????????????? IOException??
????ObjectOutputStream???ObjectInputStream??
?????????????????????????????????????????ObjectOutputStream??writeObject???????????????г??????????ObjectInputStream??readObject??????洢?а????????????
???????????ObjectInputStream??ObjectOutputStream???????????????????????????????????Java?????л??????л????????????л?????Щ???
????Transient ?????
????Transient ???????????????????????л?????????????????ù??????????????????????л???????У?????????л???transient ???????????????????? int ????? 0??????????? null??????Transient ????????????????????????Java?????л??????л?
???????л?ID
????????????????????л??????????????·???????????????£???????????????????????????л? ID ?????£??? private static final long serialVersionUID)
???????л? ID ?? Eclipse ??????????????????????????? 1L???????????????????????? long ??????????????????? JDK ?????????????????????????飬?????????????????????? 1L ?????????????????????????????л????????????????????л? ID ?????????????Щ????????????л? ID ?????????????Щ???????á?
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????