对象存在堆内存中的
把对象存在硬盘中叫做对象的持久化存储或者叫序列化
每个类都有一个固定的标记UID,就是为了序列化的方便
通过static修饰的不能序列化,transient 修饰的不能序列化
代码如下:
/*
* 每个类都有一个固定的标记UID,为了序列化方便
* static修饰的不能序列化,transient 修饰的不能序列化
实现Serializable接口该接口没有方法称之为标机接口
*/
public class persion implements Serializable{
//自定义UID
public static final long serialVersionUID=42L;
private String name;
static int age;
transient String content;
public persion(String name,int age,String count) {
this.name=name;
this.age = age;
this.content = count;
}
public String toString(){
return"name="+name+"--age="+age+"---"+content;
}
}
public class persionDemo {
public static void main(String[] args)throws Exception{
write();
reader();
}
public static void write() throws Exception{
ObjectOutputStream objout =
new ObjectOutputStream(new FileOutputStream("D:\\持久化.object"));
persion persion = new persion("张三", 31,"哈哈哈") ;
objout.writeObject(persion);
objout.close();
}
public static void reader() throws Exception{
ObjectInputStream objin =
new ObjectInputStream(new FileInputStream("D:\\持久化.object"));
persion persion = (persion)objin.readObject();
System.out.println(persion.toString());
}
}
通过SequenceInputStream实现流的合并,重要代码:
Vector<InputStream> vector = new Vector<InputStream>();
vector.add(new FileInputStream("D:\\1.park"));
vector.add(new FileInputStream("D:\\2.park"));
vector.add(new FileInputStream("D:\\3.park"));
vector.add(new FileInputStream("D:\\4.park"));
vector.add(new FileInputStream("D:\\5.park"));
Enumeration<InputStream> en= vector.elements();
SequenceInputStream sqis = new SequenceInputStream(en);
FileOutputStream out = new FileOutputStream("D:\\合并流.jpg");
int len=0;
while((len=sqis.read())!=-1){
out.write(len);
}
out.close();