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 {
/**
* Loads solution coordinates from a CSV file.
* @param filePath The path to the CSV file containing solution coordinates.
* @return A list of "row,column" formatted solution coordinates.
* @throws IOException If the file cannot be read.
*/
public static List<String> loadSolution(String filePath) throws IOException {
public static List<String> loadSolution(String resourcePath) throws IOException {
InputStream inputStream = HitoriSolutionLoader.class.getResourceAsStream(resourcePath);
if (inputStream == null) {
throw new IOException("Ressourcendatei nicht gefunden: " + resourcePath);
}
List<String> solutionCoordinates = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
boolean isSolutionSection = false;
while ((line = reader.readLine()) != null) {
// 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;
}
}