我正在尝试从格式如下的文件中提取信息:
1
test@mail.ca|password|false
但是,在运行以下代码时,我似乎遇到了ArrayIndexOutOfBounds
错误,我无法确定原因,因为我相信我的拆分应该可以正常运行。在以“用户”开头的行上获得错误。
sc = new Scanner (System.in);
BufferedReader in = new BufferedReader (new FileReader (USAVE));
int repeats = Integer.parseInt(in.readLine());
for (int c = 0; c < repeats; c++){
String info = in.readLine();
System.out.println (info);
String[] extracted = info.split("\\|");
users.addUser(extracted[0], decryptPassword(extracted[1]));
}
in.close();
可能是什么问题呢?
编辑:我改变了“|” 到“\|” 但问题仍然存在。
EDIT2:堆栈跟踪
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at OnlineCommunications.userFromFile(OnlineCommunications.java:165)
at OnlineCommunications.logIn(OnlineCommunications.java:36)
at OnlineCommunications.emailOption(OnlineCommunications.java:593)
at OnlineCommunications.main(OnlineCommunications.java:683)
我在上面发布的方法是名为userFromFile
.