Salut !
J'ai un problème de récupération du contenu de ces deux variables : n1 et n2 dans le code ci-dessous :
Merci !
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
24
25
26
27
28
29
30
31
32
33
34
35 try{ InputStream flux = new FileInputStream("file.txt"); InputStreamReader lecture = new InputStreamReader(flux); BufferedReader buff = new BufferedReader(lecture); String ligne, ligne1; while ((ligne = buff.readLine())!=null) { if(ligne.startsWith("k")) { first = Integer.parseInt(ligne.substring(6, 9)); second = Integer.parseInt(ligne.substring(10, 13)); } } while ((ligne1 = buff.readLine())!=null) { if(ligne1.startsWith("e")) { int ind1 = ligne1.lastIndexOf(" "); n1 = Integer.parseInt(ligne1.substring(2, ind1)); n2 = Integer.parseInt(ligne1.substring(ind1+1)); } } buff.close(); } catch (Exception e){ System.out.println(e.toString()); } // Je veux afficher leurs contenus ici mais elles ont comme contenu 0 System.out.println(first); // ça marche System.out.println(n1); // ça marche System.out.println(n1); // ne marche pas contenu 0 System.out.println(n2); // ne marche pas conetu 0
Partager