Here is my CSV file:
11608030,12345 11608045,54321 Here is my code:
package csvtest; import java.util.ArrayList; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Test { private ArrayList<Long> account_number = new ArrayList<Long>(); private ArrayList<String> password = new ArrayList<String>(); public Test() throws FileNotFoundException { Scanner scanner = new Scanner(new File("E:\\account.csv")); scanner.useDelimiter(","); while(scanner.hasNext()){ this.account_number.add(Long.parseLong(scanner.next())); this.password.add(scanner.next()); } System.out.println(account_number); } } and in the main class there is only one command
Test test = new Test();
but when i run this code i got a message like this
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1371) at csvtest.Test.(Test.java:28) at csvtest.CSVTest.main(CSVTest.java:21) C:\Users\hp\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)
whats wrong with my code?? need help!!! thanks in advance :)