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
|
public class Designs {
public class write {
private static final int SIZE = 5;
private final String PATH = "C:" + File.separator + "nomFichier11_11.doc";
public void writer(int n) {
Tableau tableau = new Tableau(SIZE);
tableau.display();
try {
FileWriter writer = new FileWriter(new File(PATH));
try {
tableau.writeInFile(writer);
} catch (IOException e1) {
System.out.println("Impossible d'ecrire dans le fichier");
e1.printStackTrace();
} finally {
try {
writer.close();
} catch (IOException e1) {
System.out.println("Impossible de fermer le fichier");
e1.printStackTrace();
}
}
} catch (IOException e1) {
System.out.println("Impossible de creer le fichier");
e1.printStackTrace();
}
}
}
public class Tableau {
private int[] tableau;
public Tableau(int size) {
tableau = new int[size];
fillTable(size);
display();
}
private void display() {
for (int i = 0; i < tableau.length; i++) {
System.out.println(getStringOfIndice(i));
}
}
private void fillTable(int size) {
for (int i = 0; i < size; i++) {
tableau[i] = i;
}
}
public void writeInFile(FileWriter output) throws IOException {
for (int i = 0; i < tableau.length; i++) {
output.write(getStringOfIndice(i));
}
}
private String getStringOfIndice(int i) {
return "tab[" + i + "] = " + tableau[i];
}
}
} |
Partager