Download IO_stream_project/Object_stream_module/src/case_package/Test2.java from zxy0307/Java: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/zxy0307/Java/resolve/main/IO_stream_project/Object_stream_module/src/case_package/Test2.java
- Command line
-
hf download hf://zxy0307/Java/IO_stream_project/Object_stream_module/src/case_package/Test2.java
-
curl -L -o Test2.java https://huggingface.co/zxy0307/Java/resolve/main/IO_stream_project/Object_stream_module/src/case_package/Test2.java
1.31 kB
| package case_package; | |
| import java.io.FileInputStream; | |
| import java.io.IOException; | |
| import java.io.ObjectInputStream; | |
| import java.util.ArrayList; | |
| public class Test2 { | |
| public static void main(String[] args) throws IOException, ClassNotFoundException { | |
| //1、创建反序列化流的对象 | |
| ObjectInputStream ois = new ObjectInputStream(new FileInputStream("/Users/zhaoxiaoyong" + | |
| "/Documents/Java/IO_stream_project/Object_stream_module/src/rough_draft/b.txt")); | |
| //2、读取数据 | |
| Student s1 = (Student) ois.readObject(); | |
| Student s2 = (Student) ois.readObject(); | |
| Student s3 = (Student) ois.readObject(); | |
| //EOFException: Student s4 = (Student) ois.readObject(); | |
| System.out.println(s1); | |
| System.out.println(s2); | |
| System.out.println(s3); | |
| //3、释放资源 | |
| ois.close(); | |
| //另一种方式: | |
| ObjectInputStream ois2 = new ObjectInputStream(new FileInputStream("/Users/zhaoxiaoyong" + | |
| "/Documents/Java/IO_stream_project/Object_stream_module/src/rough_draft/c.txt")); | |
| ArrayList<Student> list = (ArrayList<Student>) ois2.readObject(); | |
| for (Student student : list) { | |
| System.out.println(student); | |
| } | |
| ois2.close(); | |
| } | |
| } | |