0

I am getting an error with my code and I don't understand why. I am using OpenCsv library and trying to save my CSV into an array. The CSV has Columns that look like: Date, Sold, Code and then information under it like: 1123, may4, 0021;3323;

My code is:

 private static final String SAMPLE_CSV ="C:\\Users\\Documents\\o.csv\\";

public static void main(String[] args) throws IOException{


     { 

        try (
            Reader reader = Files.newBufferedReader(Paths.get(SAMPLE_CSV));
            CSVReader csvReader = new CSVReader(reader);
        ) {
            // Reading Records One by One in a String array
            String[] nextRecord;
            while ((nextRecord = csvReader.readNext()) != null) {
                System.out.println("Order num : " + nextRecord[0]);
                System.out.println("SoldToAct : " + nextRecord[1]);
                System.out.println("RequestedDelivery : " + nextRecord[2]);
                System.out.println("BaseCode : " + nextRecord[3]);
                 System.out.println("Option Code : " + nextRecord[4]);
                System.out.println("==========================");
            }
        }

the error is in the CSVReader csvReader = new CSVReader(reader); line.

1
  • What is the error? Commented Apr 16, 2018 at 19:08

1 Answer 1

0

Try removing the double backslashes at the end of SAMPLE_CSV:

Change from:

private static final String SAMPLE_CSV ="C:\\Users\\Documents\\o.csv\\";

To this:

private static final String SAMPLE_CSV ="C:\\Users\\Documents\\o.csv";
Sign up to request clarification or add additional context in comments.

3 Comments

It didnt work, Still get the Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/ObjectUtils error
Does stackoverflow.com/a/46034653/2848676 resolve your java.lang.NoClassDefFoundError ?
how would I download the apache commons lang

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.