Gestion des exceptions pour louverture de fichier

This commit is contained in:
David AKAGUNDUZ 2024-05-04 16:54:22 +02:00
parent f5d9276a33
commit 2ab5388dc1
11 changed files with 12 additions and 4 deletions

@ -1,6 +1,8 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@ -32,11 +34,15 @@ public class Grid {
}
System.out.println("Success");
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) {
System.err.println("Error: " + e.getMessage());
System.err.println("Erreur d'entrée/sortie: " + e.getMessage());
}
}
public void saveGridToFile(String fileName) {
try (DataOutputStream output = new DataOutputStream(new FileOutputStream(fileName))) {
for (int ligne = 0; ligne < 9; ligne++) {
@ -48,8 +54,10 @@ public class Grid {
output.writeInt(Integer.parseInt(line.toString()));
}
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) {
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();
}
}
}
}

BIN
build/Cell.class Normal file

Binary file not shown.

BIN
build/GenerateGrid.class Normal file

Binary file not shown.

BIN
build/Grid.class Normal file

Binary file not shown.

BIN
build/Sudoku.class Normal file

Binary file not shown.

Binary file not shown.

BIN
build/SudokuSolver.class Normal file

Binary file not shown.

BIN
build/SudokuUI$1.class Normal file

Binary file not shown.

BIN
build/SudokuUI$2.class Normal file

Binary file not shown.

BIN
build/SudokuUI$3.class Normal file

Binary file not shown.

BIN
build/SudokuUI.class Normal file

Binary file not shown.