I am trying to import a CSV file into an Arraylist using a StringTokenizer :
public class Test { public static void main(String [] args) { List<ImportedXls> datalist = new ArrayList<ImportedXls>(); try { FileReader fr = new FileReader("c:\\temp.csv"); BufferedReader br = new BufferedReader(fr); String stringRead = br.readLine(); while( stringRead != null ) { StringTokenizer st = new StringTokenizer(stringRead, ","); String docNumber = st.nextToken( ); String note = st.nextToken( ); String index = st.nextToken( ); ImportedXls temp = new ImportedXls(docNumber, note, index); datalist.add(temp);
I donβt understand how nextToken works, because if I save the initialization of three variables ( docNumber , note and index ) as nextToken() , it fails:
Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(Unknown Source) at _test.Test.main(Test.java:32)
If I hold only docNumber, it works. could you help me?
java arraylist import csv
gaffcz
source share