Gestion des exceptions pour louverture de fichier
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.EOFException;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -32,11 +34,15 @@ public class Grid {
|
|||||||
}
|
}
|
||||||
System.out.println("Success");
|
System.out.println("Success");
|
||||||
System.out.println(this);
|
System.out.println(this);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.err.println("Erreur : Fichier non trouvé: " + e.getMessage());
|
||||||
|
} catch (EOFException e) {
|
||||||
|
System.err.println("Erreur : Fin de fichier atteinte prématurément: " + e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Error: " + e.getMessage());
|
System.err.println("Erreur d'entrée/sortie: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveGridToFile(String fileName) {
|
public void saveGridToFile(String fileName) {
|
||||||
try (DataOutputStream output = new DataOutputStream(new FileOutputStream(fileName))) {
|
try (DataOutputStream output = new DataOutputStream(new FileOutputStream(fileName))) {
|
||||||
for (int ligne = 0; ligne < 9; ligne++) {
|
for (int ligne = 0; ligne < 9; ligne++) {
|
||||||
@@ -48,8 +54,10 @@ public class Grid {
|
|||||||
output.writeInt(Integer.parseInt(line.toString()));
|
output.writeInt(Integer.parseInt(line.toString()));
|
||||||
}
|
}
|
||||||
System.out.println("Grille sauvegardée avec succès dans " + fileName);
|
System.out.println("Grille sauvegardée avec succès dans " + fileName);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.err.println("Erreur : Fichier non trouvé: " + e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Erreur lors de la sauvegarde de la grille: " + e.getMessage());
|
System.err.println("Erreur d'entrée/sortie: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,4 +81,4 @@ public class Grid {
|
|||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user