java - Convert CSV file into 2D array using StringTokenizer -
i'm trying convert csv file 2d array i'm having problems. code seems print out first name in csv file 10 times , gives me out of bounds exception. e.g if player name rob, print out rob on , on again.
if more clarification needed ask
try{ int col = 0, row = 0; system.out.println("reading " + filename + " ..."); fr = new filereader(filename); bf = new bufferedreader(fr); string line = bf.readline(); while (line != null) { stringtokenizer st = new stringtokenizer(line,","); while(st.hasmoretokens()){ system.out.println(st.nexttoken()); data[row][col] = st.nexttoken(); col++; } col = 0; row++; } }catch(ioexception e){ system.err.println("cannot find: "+filename); }
i think code reads 1 line. continue while loop using following code snippet -
string line = bf.readline(); while ((line = br.readline()) != null) { //place code here }
in above code bufferedreader
- br
ready read next line , continues until br.readline()
returns null.
hope help.
lot.
Comments
Post a Comment