产生一个序列号
package com.mec.study.Serializable;
import java.io.Serializable;
public class DemoForSerializable implements Serializable {
private static final long serialVersionUID = -8694297154054213119L;
private int field_one;
private String field_other;
public DemoForSerializable() {
}
public int getField_one() {
return field_one;
}
public void setField_one(int field_one) {
this.field_one = field_one;
}
public String getField_other() {
return field_other;
}
public void setField_other(String field_other) {
this.field_other = field_other;
}
}
package com.mec.study.Serializable;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class Test {
public static void main(String[] args) {
try {
FileOutputStream os = new FileOutputStream("E:\\college\\programme\\JavaEE\\csdn素材"
+ "\\src\\target\\tag.bin");
ObjectOutputStream objos = new ObjectOutputStream(os);
objos.writeObject(new DemoForSerializable(54,"test"));
objos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static final long serialVersionUID = -8694297154054213119L;
/*
*
* 原码 1111 1000 1010 1000 0101 1001 0011 0010 0111 1111 0001 0111 0100 1101 1111 1111
* 补码 1000 0111 0101 0111 1010 0110 1100 1101 1000 0000 1110 1000 1011 0010 0000 0001
* 转换为十六进制:87 57 A6 CD 80 E8 B2 01
*
* */
即下图中黄颜色的框里的内容