📄 objectstream.java
字号:
import java.io.*;
import java.util.*;
public class objectStream
{
public static void main(String[] args) throws Exception
{
testobject a=new testobject(20,"haha");
testobject b=new testobject(22,"qiuqiu");
testobject c=new testobject(23,"lafan");
beanobject(a,"beanobject.txt");
beanobject(b,"beanobject.txt");
beanobject(c,"beanobject.txt");
testobject x[]=outbean("beanobject.txt");
}
public static void beanobject(Object a,String b)throws Exception {
ObjectOutputStream newout=new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(b,true)));
newout.writeObject(a);
newout.close();
}
public static testobject[] outbean(String b)throws Exception {
ObjectInputStream newin=new ObjectInputStream(new BufferedInputStream(new FileInputStream(b)));
testobject[] rt=new testobject[3];
testobject now;
int i=0;
while ((now=(testobject)newin.readObject())!=null){
now.print();
//rt[i]=now;
i++;
}
newin.close();
return rt;
}
}
class testobject implements Serializable{
private int no;
private String name;
public testobject(int no,String name){
this.no=no;
this.name=name;
}
public void print(){
System.out.println("NO is:"+no+" Name is:"+name);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -