Bonjour,
Je dois ouvrir un csv en utilisant l'api Jackson. Voilà mon code :
Il se trouve que liste.size() me retourne 0 et je ne comprend pas pourquoi ....
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public class ImportCsvTest { public static void main(String[] args) throws JsonProcessingException, IOException { System.out.println("==================================\n" + " Import CSV (Troncons) test\n" + "==================================\n"); final String MONCSV = "C:/Users/dsonfils/Documents/Mes_Projets/SAGASE/Workspace/polex-referentiel-import/src/main/csv/Troncons.csv"; List<TronconCsv> liste = ImportTronconServiceImpl.openFile(MONCSV); System.out.println(liste.size()); } } public static List<TronconCsv> openFile(String monFichier) throws JsonProcessingException, IOException{ CsvMapper mapper = new CsvMapper(); CsvSchema schema = CsvSchema.emptySchema().withHeader(); MappingIterator<TronconCsv> it = mapper.readerFor(TronconCsv.class) .with(schema). readValues(monFichier); List<TronconCsv> tronconListe = it.readAll(); return tronconListe; }
Mercie d'avance pour toutes suggestions
Partager