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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| /** Procedure permettant la sauvegarde du classement */
public void save(String nomFich) {
try {
Writer fich = new FileWriter(nomFich);
fich.write(new Integer(nbrMaxEq).toString() + "\n");
for (int i = 0; i < nbrMaxEq; i++) {
String tmp = "" + getEquipeID(i + 1).getNom() + ""
+ getEquipeID(i + 1).getPoints() + " "
+ getEquipeID(i + 1).getJournee() + ""
+ getEquipeID(i + 1).getGagnee() + " "
+ getEquipeID(i + 1).getNulle() + ""
+ getEquipeID(i + 1).getPerdu() + " "
+ getEquipeID(i + 1).getDiffBut() + "\n";
fich.write(tmp);
}
fich.close();
} catch (IOException e) {
System.err.println(nomFich + " - Erreur: " + e.toString());
}
}
/** Lecture du fichier avec les informations */
public void lireFichier(String nomFich) {
String line;
int i = 0;
boolean firstLine = true;
try {
FileReader fich = new FileReader(nomFich);
BufferedReader tampon = new BufferedReader(fich);
boolean eof = false;
while (!eof) {
line = tampon.readLine();
if (line == null)
eof = true;
else {
if (firstLine) {
int nbrEq = Integer.parseInt(line);
eq = new Equipe[nbrEq];
ind = 0;
nbrMaxEq = nbrEq;
firstLine = false;
} else {
line = line.trim();
ind = line.indexOf(' '); // indice de l'espace
String nom = line.substring(0, ind);// on recupere le nom
line = line.substring(ind);
line = line.trim();
ind = line.indexOf(' '); // espace
int Pts = Integer.parseInt(line.substring(0, ind)); // on recupere les points
ind = line.indexOf(' ');
line = line.substring(ind);
line = line.trim();
ind = line.indexOf(' ');
int J = Integer.parseInt(line.substring(0, ind));
ind = line.indexOf(' ');
line = line.substring(ind);
line = line.trim();
ind = line.indexOf(' ');
int G = Integer.parseInt(line.substring(0, ind));
ind = line.indexOf(' ');
line = line.substring(ind);
line = line.trim();
ind = line.indexOf(' ');
int N = Integer.parseInt(line.substring(0, ind));
ind = line.indexOf(' ');
line = line.substring(ind);
line = line.trim();
ind = line.indexOf(' ');
int P = Integer.parseInt(line.substring(0, ind));
ind = line.indexOf(' ');
line = line.substring(ind);
line = line.trim();
int Diff = Integer.parseInt(line);
eq[i] = new Equipe(nom, i + 1);
eq[i].setPoints(Pts);
eq[i].addJournee(J);
eq[i].addGagnee(G);
eq[i].addNulle(N);
eq[i].addPerdu(P);
eq[i].addDiffBut(Diff);
i++;
}
}
}
tampon.close();
fich.close();
} catch (IOException e) {
System.err.println(nomFich + " - Erreur: " + e.toString());
}
} |
Partager