如何創建多個序列化?現在系統只寫最後一條記錄到txt
。我想創建簡單的數據庫,它將包含客戶信息。而你認爲,這種存儲數據的方法在txt
。 ?如何創建多個序列化?
private static void WriteCustomers(){
System.out.println("|______Registration module______|");
try {
System.out.println("First name: ");
String firstName = reader.readLine();
System.out.println("Last name: ");
String lastName = reader.readLine();
.....
CustomerManagement obj = new CustomerManagement();
CustomerManagementD customerManagementD = new CustomerManagementD();
customerManagementD.setFirstName(firstName);
customerManagementD.setLastName(lastName);
.....
obj.serializeCustomers(customerManagementD);
}catch (IOException e){
e.getMessage();
}
}
public void serializeCustomers(CustomerManagementD customerManagementD) {
FileOutputStream fout = null;
ObjectOutputStream oos = null;
try {
fout = new FileOutputStream("CustomerManagement.txt");
oos = new ObjectOutputStream(fout);
oos.writeObject(customerManagementD);
System.out.println("Done");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (fout != null) {
try {
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
最後一個問題,如果我使用序列化,我將能夠編輯和刪除存儲的特定對象?