I am trying to extract information from a file that is formatted as follows:
1
[email protected]|password|false
However, I seem to be getting ArrayIndexOutOfBounds errors when running the following code and I am unable to determine the reason for this as I believe that my splitting should be functioning correctly. The error is obtained on the line beginning with "users".
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();
What could be the problem?
EDIT: I have changed "|" to "\|" but the problem persists.
EDIT2: StackTrace
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)
The method I have posted above is the one named userFromFile.