如何使用FileReader逐行读取 [英] How to read line by line by using FileReader
问题描述
感谢您的关注。
我创建了一个程序,我正在使用登录表单和注册表单。
一旦用户注册他们的电子邮件,他们的密码将被保存到 submit.txt
。然后他们将返回登录表单并输入他们的电子邮件和密码,这些邮件和密码保存在 submit.txt
。
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
.
在我的代码中,我使用Register文件的写文件和Login Form的Read文件。但是,它不起作用。我在用于读取文件的代码中知道我的问题。你可以帮我理解吗?。
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?.
非常感谢你的帮助。
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;
}
推荐答案
这是我的代码阅读来自文件:
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
**/
line = bufferreader.readLine();
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
这篇关于如何使用FileReader逐行读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!