java - Array out of bound exception -


i have text file in computer reading form java program, want build criteria. here notepad file :

   #students    #studentid   studentkey  yearlevel   studentname token       358314           432731243   12          adrian      afg56           358297           432730131   12          armstrong   yuy89           358341           432737489   12          atkins      jk671             #teachers         #teacherid  teacherkey    yearlevel teachername token            358314          432731243   12          adrian      n7acd                358297          432730131   12          armstrong   ey2c                 358341          432737489   12          atkins      f4ngh 

while reading notepad below code array out of bound exception. while debugging "  #students" value strline.length(). can solve this?

private static integer student_id_column = 0; private static integer student_key_column = 1; private static integer year_level_column = 2; private static integer student_name_column = 3; private static integer token_column = 4;  public static void main(string[] args) {     arraylist<string> studenttokens = new arraylist<string>();      try {         // open file first         // command line parameter         fileinputstream fstream = new fileinputstream("test.txt");         bufferedreader br = new bufferedreader(new inputstreamreader(fstream));         string strline;         // read file line line         while ((strline = br.readline()) != null) {             strline = strline.trim();              if ((strline.length()!=0) && (strline.charat(0)!='#')) {                 string[] students = strline.split("\\s+");                 studenttokens.add(students[token_column]);             }           }          (string s : studenttokens) {             system.out.println(s);         }          // close input stream         in.close();     } catch (exception e) {// catch exception if         system.err.println("error: " + e.getmessage());     } } 

considered charakter-sets, maybe file thought in unicode, asking ascii ? can change here:

bufferedreader br = new bufferedreader(new inputstreamreader(in, charakterset)); 

this help: java inputstream encoding/charset


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -