diff --git a/src/main/java/Overwrite.java b/src/main/java/Overwrite.java new file mode 100644 index 0000000..e35c38e --- /dev/null +++ b/src/main/java/Overwrite.java @@ -0,0 +1,21 @@ +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; + +public class Overwrite { + public static void checkIfPeselExists(File file, String firstName, String lastName, String Pesel) { + if(file.exists()) { + try { + List fileContent = new ArrayList<>(Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)); + } catch (IOException ex) { + System.out.println(ex.getMessage()); + } + + + } else { + System.out.println("Problem z odczytaniem danych z pliku."); + } + } +} diff --git a/src/main/java/Read.java b/src/main/java/Read.java index 1e2fb83..6fc2d02 100644 --- a/src/main/java/Read.java +++ b/src/main/java/Read.java @@ -25,7 +25,9 @@ public class Read { } else { boolean saved = false; - // sprawdzenie czy już siedzi w pliku + + Overwrite.checkIfPeselExists(file, personalInfo.get(1), personalInfo.get(2), personalInfo.get(3)); + if(!saved) { Write.write(personalInfo, file); System.out.println("Osoba dodana do listy."); diff --git a/src/main/java/Write.java b/src/main/java/Write.java index de90d75..b1b6a62 100644 --- a/src/main/java/Write.java +++ b/src/main/java/Write.java @@ -2,23 +2,6 @@ import java.io.*; import java.util.List; public class Write { - public static void checkIfPeselExists(File file, List data) { - if(file.exists()) { - try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { - String line; - while((line = bufferedReader.readLine()) != null) { - // - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - System.out.println("Problem z odczytaniem danych z pliku."); - } - } - public static void write(List data, File file) { if(file.exists()) { try (BufferedWriter fileWriter = new BufferedWriter(new FileWriter(file, true))){