Bonjour à tous,
J'ai un petit soucis dans une méthode pour lire un fichier, je tombe sur une erreur que je ne comprends pas et je ne vois vraiment pas où est le problème... Si quelqu'un sait m'éclairer ? :)
Dans le main :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public static Concours lire(String filename) throws IOException{ Concours temp; int tab[] = new int[NBQUESTIONS]; File file = new File(filename); Scanner inputFile = new Scanner(file); int nbParti = inputFile.nextInt(); temp = new Concours(nbParti); while(inputFile.hasNextLine()){ String nom = inputFile.nextLine(); String prenom = inputFile.nextLine(); String ecole = inputFile.nextLine(); int annee = inputFile.nextInt(); Participant p = new Participant(nom, prenom, ecole, annee, tab); temp.inscrire(p); } inputFile.close(); return temp; }
Et voici l'erreur :Code:
1
2
3 String fichier = "fichier.txt"; Concours c2 = lire(fichier); System.out.println(c2.toString());
La ligne 44 correspond à : int annee = inputFile.nextInt();Code:
1
2
3
4
5
6
7 Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at mainConcours.lire(mainConcours.java:44) at mainConcours.main(mainConcours.java:129)
et la ligne 129 à : Concours c2 = lire(fichier);
Merci :)