Java 找不到符号类FileWriter。如何修复?

Java 找不到符号类FileWriter。如何修复?,java,windows-7,persistence,bluej,Java,Windows 7,Persistence,Bluej,因此,我试图找出如何在Java中永久存储数据,我遇到了以下帖子: 我找到了这个答案: 最简单的方法是使用Properties类。它存储键/值对,并可以将数据持久化到属性文件中。下面是一个工作示例: Properties p = new Properties(); p.setProperty("johndoe.pin", "12345"); p.store(new FileWriter("myfile.properties", ""); and reading: Properties p = n

因此,我试图找出如何在Java中永久存储数据,我遇到了以下帖子:

我找到了这个答案:

最简单的方法是使用Properties类。它存储键/值对,并可以将数据持久化到属性文件中。下面是一个工作示例:

Properties p = new Properties();
p.setProperty("johndoe.pin", "12345");
p.store(new FileWriter("myfile.properties", "");
and reading:

Properties p = new Properties();
p.load(new FileReader("myfile.properties", "");
The check will be done with the properties object:

public boolean isValid(String user, String pin) {
  return pin.equals(p.getProperty(user + ".pin"));
}
这很容易,但当然没有加密。该文件以纯文本形式存储,包括PIN

我已经导入了Java.util.Properties包,其余的代码正在运行,但是我得到了错误“找不到符号类FileWriter”

以下是完整的代码:

import java.util.Properties;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class AdminGUI extends JFrame {
    Bank AccountHandler[];
    int c = 0;

    JLabel pinL;
    JLabel balL;  
    JLabel nameL;   

    JTextField pinTF;
    JTextField balTF;
    JTextField nameTF;
    JTextField resultTF;
    JTextArea listTA;

    JButton ClearB;
    JButton ListB;
    JButton CreateB;
    JButton ExitB;

    ClearButtonHandler clbHandler;
    ListButtonHandler lbHandler;
    CreateButtonHandler cbHandler;
    ExitButtonHandler ebHandler;

    Properties prop[];

public AdminGUI() 
{
    AccountHandler = new Bank[10];

    setTitle("The Bank");

    pinL = new JLabel("Enter desired PIN #: ", JLabel.RIGHT);
    balL = new JLabel ("Enter the initial deposit: ", JLabel.RIGHT);
    nameL = new JLabel ("Enter your name: ", JLabel.RIGHT);


    pinTF = new JTextField(10);
    balTF = new JTextField (10);
    nameTF = new JTextField (10);
    resultTF = new JTextField (10);
    listTA = new JTextArea (5, 10);

    ClearB = new JButton("Clear List");
    clbHandler = new ClearButtonHandler();
    ClearB.addActionListener(clbHandler);

    ListB = new JButton("List Accounts");
    lbHandler = new ListButtonHandler();
    ListB.addActionListener(lbHandler);

    CreateB = new JButton("Create");
    cbHandler = new CreateButtonHandler();
    CreateB.addActionListener(cbHandler);

    ExitB = new JButton("Exit");
    ebHandler = new ExitButtonHandler();
    ExitB.addActionListener(ebHandler);

    Container pane = getContentPane();
    pane.setLayout(new GridLayout(6,2));

    pane.add(pinL);
    pane.add(pinTF);
    pane.add(balL);
    pane.add(balTF);
    pane.add(nameL);
    pane.add(nameTF);
    pane.add(ClearB);
    pane.add(resultTF);
    pane.add(ListB);
    pane.add(listTA);
    pane.add(CreateB);
    pane.add(ExitB);

    setSize(600,400);
    setVisible(true);
}
public class CreateButtonHandler implements ActionListener {
    public void actionPerformed (ActionEvent e)
    {
        int pin;
        double bal;
        String name;

        pin=Integer.parseInt(pinTF.getText());
        bal=Double.parseDouble(balTF.getText());
        name=nameTF.getText();

        AccountHandler[c] = new Bank(pin, bal, name);
        prop[c] = new Properties();
        prop[c].setProperty("acct." + c, AccountHandler[c].pinString());
        prop[c].store(new FileWriter("bankacct.properties", ""));


        pinTF.setText("");
        balTF.setText("");
        nameTF.setText("");
        resultTF.setText("Created. Welcome, " + name + ".");
        c++;
    }
}
public class ExitButtonHandler implements ActionListener {
    public void actionPerformed (ActionEvent e) {
        System.exit(0);
    }
}
public class ListButtonHandler implements ActionListener {
    public void actionPerformed (ActionEvent e) {
        String list = "";
        for(int i = 0; i != c; i++) {
            list = list.concat(AccountHandler[i].toString());
        }
        listTA.setText(list);
    }
}
public class ClearButtonHandler implements ActionListener {
        public void actionPerformed (ActionEvent e) {
            listTA.setText("");
        }
    }
    public static void main(String[] args) {
        AdminGUI rectObject = new AdminGUI();
    }
}
这是给我带来麻烦的部分:

AccountHandler[c] = new Bank(pin, bal, name);
prop[c] = new Properties();
prop[c].setProperty("acct." + c, AccountHandler[c].pinString());
prop[c].store(new FileWriter("bankacct.properties", ""));

我是一名初级java程序员,对这一点我是新手,如果我缺少一个简单的解决方案,我很抱歉。

您需要导入java.io.FileWriter

您需要导入FileWriter,就像java中的其他类一样。