dodatkowa klasa do ewentualnego nadpisywania
This commit is contained in:
parent
7aeda6f11a
commit
ad31122ced
21
src/main/java/Overwrite.java
Normal file
21
src/main/java/Overwrite.java
Normal file
@ -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<String> 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.");
|
||||
}
|
||||
}
|
||||
}
|
@ -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.");
|
||||
|
@ -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))){
|
||||
|
Loading…
Reference in New Issue
Block a user