From 380250f60eb6b628e10d82b85dfcfe767401c892 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 28 Apr 2022 14:35:29 +0200 Subject: [PATCH] changes so that savepath can be set elsewhere --- .../zhaw/projekt2/turnierverwaltung/App.java | 2 +- .../projekt2/turnierverwaltung/FileIO.java | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java index dc9a2f3..816e6f5 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java @@ -15,7 +15,7 @@ public class App { public static void main(String[] args) { System.out.println(new App().getGreeting()); - FileIO io = new FileIO(); + FileIO io = new FileIO(System.getProperty("user.dir") + File.separator + "tournierverwaltung_angrynerds"); Tournament tournament= new Tournamenttest("helloo"); io.saveTournament(tournament); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java index 9271812..87e357a 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java @@ -1,21 +1,25 @@ package ch.zhaw.projekt2.turnierverwaltung; -import java.io.*; -import java.util.ArrayList; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.ObjectInputStream; import java.util.Arrays; import java.util.List; public class FileIO { - File saveDir; - File saves; + private File mainDir; + private File saves; - public FileIO() { - String savePath = System.getProperty("user.dir") + File.separator + "tournierverwaltung_angrynerds"; - this.saveDir = new File(savePath); - saveDir.mkdir(); - saves = new File(saveDir, "saves"); + public FileIO(String saveLocation) { + this.mainDir = new File(saveLocation); + mainDir.mkdir(); + saves = new File(mainDir, "saves"); saves.mkdir(); } @@ -29,6 +33,7 @@ public class FileIO { ObjectInputStream in = new ObjectInputStream(new FileInputStream(tournamentFile)); tournament = (Tournament) in.readObject(); in.close(); + System.out.println("Save File" + tournament.getName() + ".txt being saved to " + saves.getAbsolutePath()); } catch (ClassNotFoundException | IOException e) { throw new RuntimeException(e);