如何使特定用户在JFileChooser中查看他们自己的文本文件? JAVA

时间:2018-11-27 06:25:57

标签: java eclipse swing

我正在尝试为某个学生登录时设置代码,以便他们能够查看自己的成绩。我认为我目前设置代码的方式是,每个学生都可以查看自己的成绩。但是,无论哪个学生登录,他们都可以查看不需要的当前目录中的所有文本文件。我做错了什么吗?

First student is logged in (should only see hw 1)

Student 2 is logged in (shouldn't be able to see hw1, but does)

  // 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);
            }


        }
        }
    });

0 个答案:

没有答案