-2

我正在尝试加载我保存的一个简单类的文件。您可以在下面找到我用来加载的代码,我需要转换的类是 NewClientClass。

JFileChooser fc = new JFileChooser();
        int returnVal = fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            ObjectInputStream  in = new ObjectInputStream(new FileInputStream(fc.getSelectedFile().getAbsoluteFile()));
            // = (NewClientClass) in.readObject();
            in.close();
            //IDNumber.setText();
        }

您可以在下面找到我用来保存数据的代码。

 NewClientClass AddClient = new NewClientClass(IDNumber.getText(), FirstName.getText(), LastName.getText(), Address.getText(), DateOfBirth.getText(), Profession.getText());
       try {   
        int returnVal = fc.showSaveDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(fc.getSelectedFile().getAbsoluteFile()));
            out.writeObject(AddClient);
            out.close();
            JOptionPane.showMessageDialog(null, "Successfully Saved");

谁能帮我加载 NewClientClass 的文件,以便之后我可以在文本框中显示详细信息。

谢谢

4

1 回答 1

0

You should be almost there:

if (returnVal == JFileChooser.APPROVE_OPTION) {
            ObjectInputStream  in = new ObjectInputStream(new FileInputStream(fc.getSelectedFile().getAbsoluteFile()));
            NewClientClass loadedObject = (NewClientClass) in.readObject();
            in.close();
            IDNumber.setText(loadedObject.getIDNumber());
            ...//Do the rest here.
            //IDNumber.setText();
        }
于 2013-07-16T13:00:53.787 回答