Java – how to read line by line using FileReader

Thank you for your attention

I created a program and I am using the login form and registration form Once users register their email, their password will be saved to submit txt. Then they will return to the login form and save the input in submit Txt

In my code, I use the write file of register file and the read file of login form But it doesn't work I know my problem in the code used to read the file Can you help me achieve it?

Thank you very much for your help

if (checkPassword(usern,hash)) {
    System.out.println("Logged in!");
    ChooseWindow ptb = new ChooseWindow();
    ptb.setVisible(true);
    LoginWindow.this.dispose();
 } else {
    System.out.println("Wrong password");
 }

 public boolean checkPassword(String username,String pass) {
    try {
        FileReader inFile = new  FileReader("/users/Ender/Desktop/GetUser/submit.txt");
        BufferedReader inStream = new BufferedReader(inFile);
        String inString;

        while ((inString = inStream.readLine()) != null) {}
        inStream.close();                       
    }catch (IOException e) {
        e.printStackTrace();
    }
    return false;
 }

Solution

This is the code I read from the file:

String line;

    try {

        BufferedReader bufferreader = new BufferedReader(new FileReader("C:\\Users\\ahmad\\Desktop\\aaa.TXT"));


        while ((line = bufferreader.readLine()) != null) {     
          /** 
            Your implementation  
          **/
            line = bufferreader.readLine();
        }

    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>