l'export fonctionne
This commit is contained in:
parent
0e0e415d48
commit
6cc2e83b9a
|
|
@ -17,21 +17,26 @@ public class ListeAvis {
|
|||
private void lireCSV(String filePath) {
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
|
||||
String ligne;
|
||||
br.readLine();
|
||||
br.readLine(); // Ignore l'en-tête
|
||||
|
||||
while ((ligne = br.readLine()) != null) {
|
||||
String[] valeurs = ligne.split(",");
|
||||
if (valeurs.length < 4) continue;
|
||||
String[] valeurs = ligne.split(";", 4); // Séparation avec ";"
|
||||
|
||||
// Vérifie que la ligne contient exactement 4 colonnes
|
||||
if (valeurs.length != 4) {
|
||||
System.err.println("Ligne ignorée (format incorrect) : " + ligne);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
int numeroFilm = Integer.parseInt(valeurs[0].trim());
|
||||
String url = valeurs[1].trim();
|
||||
String commentaire = valeurs[2].trim();
|
||||
int polarite = Integer.parseInt(valeurs[valeurs.length-1].trim());
|
||||
String commentaire = valeurs[3].trim();
|
||||
int polarite = Integer.parseInt(valeurs[2].trim());
|
||||
|
||||
listeAvis.add(new Avis(numeroFilm, url, commentaire, polarite));
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Erreur de format dans la ligne : " + ligne);
|
||||
System.err.println("Erreur de conversion dans la ligne : " + ligne);
|
||||
}
|
||||
}
|
||||
System.out.println("Fichier CSV chargé avec succès !");
|
||||
|
|
@ -49,8 +54,8 @@ public class ListeAvis {
|
|||
System.out.println("------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
public List<Avis> getListeAvis() {
|
||||
return listeAvis;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package Main;
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
String cheminFichierExcel = "C:\\Users\\Qpelu\\Downloads\\mini.csv";
|
||||
String cheminFichierExcel = "C:\\Users\\Qpelu\\Downloads\\big.csv";
|
||||
ListeAvis listeAvis = new ListeAvis(cheminFichierExcel);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue