java - Univocity Parsers: Is there a way to select a col, and if it doesn't exist in the file, have the parser parse the col name and values in it as "null"? -


is there way select column, , if doesn't exist in .csv file, have parser parse column name , values in "null" or "empty"?

should work fine:

@test public void fieldselectiontest() throws exception {     csvparsersettings settings = new csvparsersettings();     settings.setheaderextractionenabled(true);     settings.getformat().setlineseparator("\n");     settings.setnullvalue("n/a"); //null value here      settings.selectfields("year", "???");      csvparser parser = new csvparser(settings);      string input = "" +             "year,header1,header2\n" +             "2000,foo,bar\n" +             "2016,blah,etc\n";      for(string[] row : parser.parseall(new stringreader(input))){         system.out.println(arrays.tostring(row));     } } 

will print:

[2000, n/a] [2016, n/a] 

hope helps


Comments

Popular posts from this blog

php - trouble displaying mysqli database results in correct order -

depending on nth recurrence of job in control M -

sql server - Cannot query correctly (MSSQL - PHP - JSON) -