class myPoint implements Serializable{
}
void writeExternal(ObjectOutput out) throws IOException;
void readExternal(ObjectInput in) throws IOException,ClassNotFoundException;
public class Point implements Externalizable {
private int a;
private int b;
public Point(int a, int b) {
this.a = a;
this.b = b;
}
public Point() {
}
public String toString() {
return a + " , " + b;
}
public void writeExternal(ObjectOutput out) throws IOException {
out.write(a);
out.write(b);
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
a = in.read();
b = in.read();
}
public static void main(String[] args) throws IOException,
ClassNotFoundException {
String file = "d://1.txt";
Point p = new Point(1, 2);
System.out.println(p);
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(p);
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
Point pp = (Point) ois.readObject();
System.out.println(pp);
}
}
public class StringList implements Serializable {
private transient int size = 0;
private transient Entity head = null;
public final void add(String str) {
// ...
}
private static class Entity {
String data;
Entity next;
Entity previous;
}
private void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
s.write(size);
for (Entity e = head; e != null; e = e.next) {
s.writeObject(e.data);
}
}
private void readObject(ObjectInputStream s) throws IOException,
ClassNotFoundException {
s.defaultReadObject();
int num = s.read();
for (int i = 0; i < num; i++) {
this.add((String) s.readObject());
}
}
}
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Date;
public final class Period implements Serializable {
private static final long serialVersionUID = 100L;
private final Date start;
private final Date end;
public Period(Date start, Date end) {
this.start = new Date(start.getTime());
this.end = new Date(end.getTime());
if (this.start.compareTo(this.end) > 0) {
throw new IllegalArgumentException(start + " after " + end);
}
}
public Date start() {
return new Date(start.getTime());
}
public Date end() {
return new Date(end.getTime());
}
public String toString() {
return start + " - " + end;
}
// 不给
private Object writeReplace() {
return new SerializationProxy(this);
}
private void readObject(ObjectInputStream stream)
throws InvalidObjectException {
throw new InvalidObjectException("proxy request");
}
private static class SerializationProxy implements Serializable {
private final Date start;
private final Date end;
SerializationProxy(Period p) {
this.start = p.start;
this.end = p.end;
}
private Object readResolve() {
return new Period(start, end);
}
private static final long serialVersionUID = 1000L;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有