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 e06a54c..d00a1a6 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java @@ -10,5 +10,8 @@ public class App { public static void main(String[] args) { System.out.println(new App().getGreeting()); + FileIO io = new FileIO(); + Tournament tournament= new Tournamenttest("hello"); + 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 new file mode 100644 index 0000000..ca86b5c --- /dev/null +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java @@ -0,0 +1,51 @@ +package ch.zhaw.projekt2.turnierverwaltung; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + + +public class FileIO { + File saveDir; + File saves; + + + public FileIO() { + String savePath = System.getProperty("user.dir")+File.separator+"tournierverwaltung_angrynerds"; + this.saveDir = new File(savePath); + saves = new File(saveDir, "saves"); + } + + public void getList() { + + } + + public void loadTournament(Tournament tournament) { + + } + + public void saveTournament(Tournament tournament) { + File newSave = new File(saves, tournament.getName()+".txt"); + try { + newSave.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(newSave)); + out.writeObject(tournament); + out.close(); + System.out.println("Save File" + tournament.getName()+".txt being saved to " + saves.getAbsolutePath()); + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public void getTournament(String storageSpace) { + + } + +} diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java index c6d6211..4b6b8de 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -1,6 +1,8 @@ package ch.zhaw.projekt2.turnierverwaltung; -public abstract class Tournament { +import java.io.Serializable; + +public abstract class Tournament implements Serializable { private String name; public Tournament(String name){