加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何使用FileReader逐行读取

发布时间:2020-12-14 05:56:25 所属栏目:Java 来源:网络整理
导读:感谢您的关注. 我创建了一个程序,我正在使用登录表单和注册表单. 一旦用户注册他们的电子邮件,他们的密码将被保存到submit.txt.然后他们将返回登录表单并输入保存在submit.txt中的电子邮件和密码. 在我的代码中,我使用Register文件的写文件和Login Form的Rea
感谢您的关注.

我创建了一个程序,我正在使用登录表单和注册表单.
一旦用户注册他们的电子邮件,他们的密码将被保存到submit.txt.然后他们将返回登录表单并输入保存在submit.txt中的电子邮件和密码.

在我的代码中,我使用Register文件的写文件和Login Form的Read文件.但是,它不起作用.我在用于读取文件的代码中知道我的问题.你可以帮我实现吗?

非常感谢你的帮助.

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

解决方法

这是我从文件中读取的代码:
String line;

    try {

        BufferedReader bufferreader = new BufferedReader(new FileReader("C:UsersahmadDesktopaaa.TXT"));


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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读