Java 初学者-javaIO7

今天学习了什么?

import java.io.*;
import java.util.List;
public class ObjectInputStream02 {
    public static void main(String []args) throws Exception{
     ObjectInputStream oi=new ObjectInputStream(new FileInputStream("students1"));
     List<Student> st=(List<Student>) oi.readObject();
     for(Student stu:st) {
         System.out.println(stu);
     }
     oi.close(); 
    
    }
 }
View Code
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class ObjectOutputStreamTest02 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        List<Student> student=new ArrayList<>();
        student.add(new Student("111","张三"));
        student.add(new Student("222","李四"));
        student.add(new Student("333","王五"));
        try {
            ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("students1"));
            oos.writeObject(student);
            oos.flush();
            oos.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
View Code

 

明天学习什么?

明天继续学习javaIO操作。

posted @ 2020-08-09 21:21  好吗,好  阅读(92)  评论(0)    收藏  举报