Java中的ReadLine方法

Java中的ReadLine方法,java,swing,login,Java,Swing,Login,我正在尝试制作一个程序,要求用户在使用前先登录。我创建了一个注册按钮,将用户名和密码保存在两个不同的文本文件中。当用户按下登录按钮时,程序应检查第一个文件的用户名是否与第二个文件的密码匹配。我想知道如何对登录按钮进行编码(顺便说一句,不要介意名称,它们是法语的) 这是我的注册按钮的代码: public class Enregistrement extends GuiLogIn { public class Enregistrement() { registerButton.addA

我正在尝试制作一个程序,要求用户在使用前先登录。我创建了一个注册按钮,将用户名和密码保存在两个不同的文本文件中。当用户按下登录按钮时,程序应检查第一个文件的用户名是否与第二个文件的密码匹配。我想知道如何对登录按钮进行编码(顺便说一句,不要介意名称,它们是法语的)

这是我的注册按钮的代码:

public class Enregistrement extends GuiLogIn {


public class Enregistrement() {

    registerButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            nom = userText.getText();
            motDePass = passwordText.getText();

            if (!nom.equals("") ){
                if (!motDePass.equals("")) {
                    try {
                        fichierInscriptionNom = new FileWriter("C:\\Users\\bhuglahm\\Desktop\\Utilisateur.txt", true);
                        fichierInscriptionMotDePasse = new FileWriter("C:\\Users\\bhuglahm\\Desktop\\Mot de passes.txt", true);
                        tampon1= new BufferedWriter(fichierInscriptionMotDePasse);
                        tampon = new BufferedWriter(fichierInscriptionNom);
                        tampon.write(nom+"\r\n");
                        tampon1.write(motDePass+"\r\n");

                            JOptionPane.showMessageDialog(null,  "Votre comte est enrigistré avec succées","Enrigistrement", JOptionPane.INFORMATION_MESSAGE);

                    } catch (IOException e1) {

                             e1.printStackTrace();
                    }
                    finally {
                       try{
                           tampon.flush();
                           tampon.close();  
                           fichierInscriptionNom.close();
                           tampon1.flush();
                           tampon1.close(); 
                           fichierInscriptionMotDePasse.close();

                      }
                      catch (IOException ex) {
                          ex.printStackTrace();
                      }
                   }
                }else JOptionPane.showMessageDialog(null,  "Veulliez entrer votre mot de pass ","Enrigistrement", JOptionPane.INFORMATION_MESSAGE);
            }else JOptionPane.showMessageDialog(null,  "Veulliez entrer votre nom d'utilisateur","Enrigistrement", JOptionPane.INFORMATION_MESSAGE);
         }
      });
   }
 }

一开始我认为你的方式不太好,最好把用户名和密码保存在同一个文件中。但使用此代码,您可以读取文件的行:

试一试{

}捕获(异常IOException){

}最后{

   bufferedReader.close();
}


什么事=null表示?它检查文件的结尾(BufferReader在到达文件结尾时返回null)。检查此链接:
   bufferedReader.close();