csv - getting alternate column names while reading a line using buffered reader in java? -
i using code read line in csv , column names,but problem getting alternate cloumn names.it skipping first column reading second , skipping third , reading fourth..
bufferedreader br = new bufferedreader(new filereader(csvfile)); string line = ""; stringtokenizer st = null; int linenumber = 0; int tokennumber = 0; //read comma separated file line line while ((line = br.readline()) != null) { linenumber++; //use comma token separator st = new stringtokenizer(line, ","); while (st.hasmoretokens()) { //tokennumber++; s.add(st.nexttoken()); //display csv values system.out.print(st.nexttoken() + " "); }
you calling st.nexttoken() twice in while loop. each time, grab next element.
you may want replace stringtokenizer line.split(",") unless have particular need use (such performance).
Comments
Post a Comment