java之ObjectOutputStream与ObjectInputStream的使用案例

来源:互联网 发布:软考初级程序员真题 编辑:程序博客网 时间:2024/04/29 17:07
BufferedWriter b=new BufferedWriter(new FileWriter("C:/Users/lsy/Desktop/1.txt",true));b.newLine();b.write("7889uojojtfy");b.newLine();b.write("oirgorbkotoht");b.close();FileInputStream f=new FileInputStream("C:/Users/lsy/Desktop/1.txt");FileOutputStream fo=new FileOutputStream("C:/Users/lsy/Desktop/2.txt", true);byte[] by=new byte[1024];//int read = f.read(by);int i=0;while ((i=f.read(by))>0) {//System.out.println(by);fo.write(by);}f.close();fo.close();FileOutputStream fos = new FileOutputStream("3.txt");ObjectOutputStream oos=new ObjectOutputStream(fos);oos.writeObject(new Persion("lsy", "男", 22));oos.close();ObjectInputStream ois=new ObjectInputStream(new FileInputStream("3.txt"));Object object = ois.readObject();Persion p=(Persion) object;System.out.println(p.getName());p.say();
阅读全文
0 0
原创粉丝点击