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