How to read line by line by using FileReader

Ender phan picture Ender phan · Nov 24, 2015 · Viewed 28.1k times · Source

Thank you for your attention.

I have created a program which I'm using a Login form and Register form. Once users register their email and their password will be saved it into submit.txt. Then they will turn back to login form and enter their email and password which are saved into submit.txt.

In my code, I'm using write file for Register form, and Read file for Login Form. But, it doesn't work. I know my problem in the code used for Read File. May you help me to realize that?.

Thank you too 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;
 }

Answer

Ahmad Alkhatib picture Ahmad Alkhatib · Nov 24, 2015

here is my code to read from a file :

 String line;

    try {

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


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

        }

    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }