次のようにフォーマットされたファイルから情報を抽出しようとしています。
1
test@mail.ca|password|false
ただし、ArrayIndexOutOfBounds
次のコードを実行するとエラーが発生するようで、分割が正しく機能していると思われるため、その理由を特定できません。「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();
何が問題なのですか?
編集:「|」を変更しました 「\|」に しかし、問題は解決しません。
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
。