0

As in the title is in Super CSV possibility to read two files at once. The code below show the example for one file.csv:

public class Reading {  
    private static final String CSV_FILENAME1 = "src/test/resources/test1/customers.csv";
    public static void partialReadWithCsvMapReader() throws Exception {     
        ICsvMapReader mapReader1 = null;
        try {
            mapReader1 = new CsvMapReader(new FileReader(CSV_FILENAME1), CsvPreference.STANDARD_PREFERENCE);            
            mapReader1.getHeader(true);
            final String[] header = new String[] { "customerNo", "firstName", "lastName", null, null, null, null, null,
                null, null, "TOMEK" };
            final CellProcessor[] processors = new CellProcessor[] { new UniqueHashCode(), new NotNull(),
                new NotNull(), new NotNull(), new NotNull(), new Optional(), new Optional(), new NotNull(),
                new NotNull(), new LMinMax(0L, LMinMax.MAX_LONG), new NotNull()};           
            Map<String, Object> customerMap;
            while( (customerMap = mapReader1.read(header, processors)) != null ) {
                System.out.println(String.format("lineNo=%s, rowNo=%s, customerMap=%s", mapReader1.getLineNumber(),
                    mapReader1.getRowNumber(), customerMap));
            }
        }
        finally {
            if( mapReader1 != null ) {
                mapReader1.close();
            }
        }
    }

}

One solution is to declare the second variable CSV_FILENAME2:

private static final String CSV_FILENAME1 = "src/test/resources/test1/customers.csv";

and so on, but is there any other possibility? Thanks.

user3455638
  • 569
  • 1
  • 6
  • 17
  • What does "at once mean"? Concurrently? Sequentially? What do you have as input, and what do you want as output? – JB Nizet Apr 13 '14 at 13:23

1 Answers1

0

Each CsvReader can only read from a single Reader (which is passed as a constructor argument) - in other words, you can only read one CSV file per CsvReader.

As JB Nizet has commented - you really need to define what you mean by 'at once'. But whether that's concurrently, sequentially, or something else you're still going to need two instances of CsvMapReader.

Is there a requirement that the files be processed together (e.g. combining 2 CSV files into 1) or are you just looking for a way to process multiple files in general?

James Bassett
  • 9,458
  • 4
  • 35
  • 68
  • "Is there a requirement that the files be processed together (e.g. combining 2 CSV files into 1)" -> Yes I am looking something like this. – user3455638 Apr 14 '14 at 11:33