changes so that savepath can be set elsewhere

This commit is contained in:
Leonardo Brandenberger 2022-04-28 14:35:29 +02:00
parent e1fdc5deac
commit 380250f60e
2 changed files with 15 additions and 10 deletions

View File

@ -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);

View File

@ -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);