【发布时间】:2014-02-18 11:23:16
【问题描述】:
import java.io.FileInputStream;
import java.io.FileOutputStream;
try {
FileInputStream inFile_Customer = new FileInputStream("database\\Customers.bin");
ObjectInputStream ois_Customer = new ObjectInputStream(inFile_Customer);
customerList = (ArrayList<Customer>)ois_Customer.readObject();
FileInputStream inFile_Package = new FileInputStream("database\\Packages.bin");
ObjectInputStream ois_Package = new ObjectInputStream(inFile_Package);
packageList = (ArrayList<Packages>)ois_Package.readObject();
FileInputStream inFile_Order = new FileInputStream("database\\Orders.bin");
ObjectInputStream ois_Order = new ObjectInputStream(inFile_Order);
orderList = (ArrayList<Order>)ois_Order.readObject();
FileInputStream inFile_Invoice = new FileInputStream("database\\Invoices.bin");
ObjectInputStream ois_Invoice = new ObjectInputStream(inFile_Invoice);
invoiceList = (ArrayList<Invoice>)ois_Invoice.readObject();
} catch (ClassNotFoundException |IOException | ClassCastException e) {
e.printStackTrace();
}
public void WriteCustomer(){
try {
FileOutputStream fos = new FileOutputStream("database\\Customers.bin");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(customerList);
oos.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
public void WritePackage(){
try {
FileOutputStream fos = new FileOutputStream("database\\Packages.bin");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(packageList);
oos.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
public void WriteOrder(){
try {
FileOutputStream fos = new FileOutputStream("database\\Orders.bin");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(orderList);
oos.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
public void WriteInvoice(){
try {
FileOutputStream fos = new FileOutputStream("database\\Invoices.bin");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(invoiceList);
oos.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
这是我的编码。它没有显示任何错误,但它无法正常工作。信息写入文件中。但它就是无法读取里面的文件。请帮我。我是java新手。非常感谢。如果您要求检查,我可以将我的完整代码发送给您。谢谢。
【问题讨论】:
-
定义“无法工作”和“无法读取里面的文件”。