我要做的是将文本框中的信息保存到文本文件中。加载文本文件时,文本框将被填充信息。在保存文件时,我遇到了一个异常错误,如下所示:Exception e.printStackTrace(); 感谢您的帮助。
private void savecustButtonActionPerformed(java.awt.event.ActionEvent evt) {
Customer customer = new Customer();
try {
FileOutputStream fos = new FileOutputStream("Customers/" + custidTF.getText() + ".txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
customer.setPersonName((custnameTF.getText()));
customer.setPersonSurname((custsurnameTF.getText()));
customer.setPersonID((custidTF.getText()));
oos.writeObject(customer);
oos.close();
} catch (IOException e) {
}
dispose();
private void loadCustomerActionPerformed(java.awt.event.ActionEvent evt) {
Customer customerfile = null;
try {
final JFileChooser chooser = new JFileChooser("Customers/");
int chooserOption = chooser.showOpenDialog(null);
chooserOption = JFileChooser.APPROVE_OPTION;
File file = new File(chooser.getSelectedFile().getAbsolutePath());
ObjectInputStream in = new ObjectInputStream(
new FileInputStream(file)
);
customerfile = (Customer) in .readObject(); in .close();
} catch (IOException ex) {
System.out.println("Error loading file.");
} catch (ClassNotFoundException ex) {
System.out.println("Invalid class in loaded file.");
}
}
IOException ex
中获取更多的信息吗? - Wai Ha LeeIOException
中获取更多信息,例如使用getMessage
... - Wai Ha Lee