Methode verbessert wegen Fehler

currentStatus
Vickvick2002 2025-01-03 18:18:41 +01:00
parent cb97bd32eb
commit 99f0b2627b
1 changed files with 20 additions and 9 deletions

View File

@ -8,20 +8,31 @@ import java.util.*;
*/ */
public class HitoriSolutionLoader { public class HitoriSolutionLoader {
/** public static List<String> loadSolution(String resourcePath) throws IOException {
* Loads solution coordinates from a CSV file. InputStream inputStream = HitoriSolutionLoader.class.getResourceAsStream(resourcePath);
* @param filePath The path to the CSV file containing solution coordinates. if (inputStream == null) {
* @return A list of "row,column" formatted solution coordinates. throw new IOException("Ressourcendatei nicht gefunden: " + resourcePath);
* @throws IOException If the file cannot be read. }
*/
public static List<String> loadSolution(String filePath) throws IOException {
List<String> solutionCoordinates = new ArrayList<>(); List<String> solutionCoordinates = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line; String line;
boolean isSolutionSection = false;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
solutionCoordinates.add(line.trim()); // Erkenne den Abschnitt für die Lösung
if (line.startsWith("//Lösung")) {
isSolutionSection = true;
continue; // Überspringe die Kommentarzeile
}
if (isSolutionSection) {
solutionCoordinates.add(line.trim());
}
} }
} }
return solutionCoordinates; return solutionCoordinates;
} }
} }