I'm getting a "java.lang.ArrayIndexOutOfBoundsException:10" error on my "if" statement even though the file im getting the data from has an index enough to be 10.
When I call info[10] in other places in my code it works but i dont know why it's not working here.
learning file management unit in computer science right now...
public static void comSci(String onTheMap) throws IOException
{
BufferedReader input = new BufferedReader (new FileReader ("data.txt"));
if (onTheMap.equals("3")){
Scanner scanner = new Scanner("data.txt");
String line="x";
System.out.println("--------------------------------------------------------------");
System.out.println("Create a file of student's who are enrolled in ICS3U0:");
System.out.println("--------------------------------------------------------------");
String info[] = new String[20];
boolean finder = false;
while (line!=null) {
line = input.readLine();
if (line==null)
break;
info = line.split(",");
if (info[10].toLowerCase().contains("ICS3U0".toLowerCase())) { //PROBLEM
finder = true;
String programmers = info[0] + "," + info[1];
System.out.println(programmers);
try {
FileWriter theFile = new FileWriter("ICS3U0.txt",true);
PrintWriter names = new PrintWriter(theFile);
names.println();
names.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
System.out.println("ICS3U0.TXT WAS CREATED");
}
input.close();
}