Как создать систему архивирования и чтения на Java посредством сериализации?JAVA

Программисты JAVA общаются здесь
Anonymous
Как создать систему архивирования и чтения на Java посредством сериализации?

Сообщение Anonymous »


This is an exercise question in the book. The title is to design a simple employee information system that can input data and display the input data. An extension of this exercise requires me to design an save option to output the objects in the array into a tmp file.

I have successfully created the saved options now. But I think the current method is a bit tedious and requires multiple calls to the method in the class. enter image description here

But I can't put the ObjectOutputStream directly in the class, an IOException will occur. In addition, the next question requires me to create an option to read files. I don't know how I can import the data directly into the array after reading it.

package myJava.exercise.ch12; import java.io.BufferedReader; import java.lang.*; import java.util.Scanner; import java.io.*; public class ex12_06 { public static void main(String args[])throws IOException { CPersonAccount obj = new CPersonAccount(); char runFunc='d'; Scanner keyboardInput = new Scanner(System.in); while(runFunc!='q') { System.out.print("請選擇作業"); System.out.print("(i=輸入資料 s=依月薪資排序 d=顯示資料 q=離開 S=存檔):"); runFunc = keyboardInput.nextLine().charAt(0); switch (runFunc) { case 'i': obj.inputData(); break; case 's': obj.sortBySalary(); break; case 'd': obj.displayData(); break; case 'S': FileOutputStream fo = new FileOutputStream("C:\\myJava\\exercise\\ch12\\file\\ex6.tmp"); ObjectOutputStream os = new ObjectOutputStream(fo); for(int i=0;i

Источник: https://stackoverflow.com/questions/780 ... ialization

Вернуться в «JAVA»