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.

val
  • 11
  • 4

1 Answers1

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";
Michael Osofsky
  • 11,429
  • 16
  • 68
  • 113