【发布时间】:2016-02-06 23:28:08
【问题描述】:
我正在处理一个班级项目的密码登录部分。没有什么花哨。用户或角色将是一个 int,密码是一个字符串。我现在只是使用简单的加密。我遇到的问题是在读取文件时出现输入不匹配。我过去做过类似的事情,需要我阅读整数和字符串并且没有任何问题。但我只是无法弄清楚在这种情况下出了什么问题。对于我为什么会收到此错误的任何帮助将不胜感激。我正在使用while(inputStream.hasNextLine()),然后阅读int,然后阅读String,我尝试过hasNextInt 和hasNext,并不断收到相同的错误。
public void readFile(){
Scanner inputStream = null;
try {
inputStream = new Scanner (new FileInputStream("login.txt"));
}catch (FileNotFoundException e) {
e.printStackTrace();
}
if(inputStream != null){
while (inputStream.hasNextLine()){
int luser = inputStream.nextInt();
String lpass = inputStream.nextLine();
newFile[count] = new accessNode(luser, lpass);
count ++;
}
inputStream.close();
}
}
【问题讨论】:
-
您需要发布实际错误以获得良好帮助 - 即显示哪一行失败和堆栈跟踪的实际错误消息。
标签: java file inputstream fileinputstream