我正在尝试为某个学生登录时设置代码,以便他们能够查看自己的成绩。我认为我目前设置代码的方式是,每个学生都可以查看自己的成绩。但是,无论哪个学生登录,他们都可以查看不需要的当前目录中的所有文本文件。我做错了什么吗?
// student text file, this opens the StudentPassword.txt file
StudentPassFile studacc = new StudentPassFile();
studacc.openFile();
studacc.read_file();
JButton btnNewButton = new JButton("View Grades");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (StudentPassFile.map.get(AccountLogin.user) != null && StudentPassFile.map.get(AccountLogin.user).equals(AccountLogin.passw)) // IF STUDENT ACCOUNT
{
AccountLogin.currentAccount = AccountLogin.user;
StudentPassFile.password = AccountLogin.passw;
FileSystemView fsv = new DirectoryRestrictedFileSystemView(new File("Grades"));
JFileChooser chooser = new JFileChooser(fsv.getHomeDirectory(),fsv);
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
String nameFile = f.getAbsolutePath();
try {
FileReader reader = new FileReader(nameFile);
BufferedReader br = new BufferedReader(reader);
jTextArea1.read(br, null);
br.close();
jTextArea1.requestFocus();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
});