Uploaded image for project: 'Commons CSV'
  1. Commons CSV
  2. CSV-312

CSV Header with multiple lines throughs error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Parser
    • None

    Description

      CSV file header is in multi-line while trying to read the file invalid char between encapsulated token and delimiter error is thrown

       

      Sample CSV:

       

      "SYMBOL
      ","COMPANY
      ","PURPOSE
      ","DETAILS
      ","DATE
      "
      "AURIONPRO","Aurionpro Solutions Limited","Fund Raising","To consider and approve the Issue price, including a discount if any","08-Apr-2024"
      "CUPID","Cupid Limited","Financial Results/Other business matters","To consider and approve the financial results for the period ended March 31, 2024 and other business matters","08-Apr-2024"
      "DPWIRES","D P Wires Limited","Other business matters","To consider other business matters","08-Apr-2024" 

      Code used to read

       

       

      Reader in = new FileReader(file);
      
      Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(in);
      
      for (CSVRecord record : records) {
        System.out.println(record.get(0));
      } 

      Occurring Error : 

      Exception in thread "main" java.io.UncheckedIOException: IOException reading next record: java.io.IOException: (line 2) invalid char between encapsulated token and delimiter
          at org.apache.commons.csv.CSVParser$CSVRecordIterator.getNextRecord(CSVParser.java:150)
          at org.apache.commons.csv.CSVParser$CSVRecordIterator.hasNext(CSVParser.java:160)
          at com.gautham.stockmarket.tools.Main.main(Main.java:21)
      Caused by: java.io.IOException: (line 2) invalid char between encapsulated token and delimiter
          at org.apache.commons.csv.Lexer.parseEncapsulatedToken(Lexer.java:369)
          at org.apache.commons.csv.Lexer.nextToken(Lexer.java:290)
          at org.apache.commons.csv.CSVParser.nextRecord(CSVParser.java:770)
          at org.apache.commons.csv.CSVParser$CSVRecordIterator.getNextRecord(CSVParser.java:148)
          ... 2 more 

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            gautham_arunachalam Gautham Arunachalam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: