update io syntax
This commit is contained in:
parent
d9cd9f2c21
commit
d66b72ad11
1 changed files with 5 additions and 7 deletions
|
@ -99,12 +99,10 @@ public class Game {
|
|||
return null;
|
||||
|
||||
Path checkoutsFile = Path.of("src/de/dhbw_ka/probe_pe/darts_counter/checkouts.txt");
|
||||
try {
|
||||
BufferedReader reader = Files.newBufferedReader(checkoutsFile, StandardCharsets.UTF_8);
|
||||
try (BufferedReader reader = Files.newBufferedReader(checkoutsFile, StandardCharsets.UTF_8)) {
|
||||
for (int i = 0; i < (points - 1); i++)
|
||||
reader.readLine();
|
||||
String checkout = reader.readLine();
|
||||
reader.close();
|
||||
if (!checkout.equals("-"))
|
||||
return checkout;
|
||||
} catch (IOException e) {
|
||||
|
@ -157,10 +155,10 @@ public class Game {
|
|||
private void writeWinnerToFile(Player winner) {
|
||||
Path winnerFile = Paths.get("highscores.txt");
|
||||
|
||||
try {
|
||||
BufferedWriter writer = Files.newBufferedWriter(winnerFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
writer.write(winner.getName() + " won with " + winner.getCountDartsThrown() + " darts.\n");
|
||||
writer.close();
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(winnerFile, StandardCharsets.UTF_8,
|
||||
StandardOpenOption.APPEND)) {
|
||||
writer.write(winner.getName() + " won with " + winner.getCountDartsThrown() + " darts.");
|
||||
writer.newLine();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Failed to write highscore file.");
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue