Created classes to test FileIO

This commit is contained in:
Leonardo Brandenberger 2022-04-24 22:06:03 +02:00
parent 3dfa71dab1
commit e0b1616edf
3 changed files with 57 additions and 1 deletions

View File

@ -10,5 +10,8 @@ public class App {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(new App().getGreeting()); System.out.println(new App().getGreeting());
FileIO io = new FileIO();
Tournament tournament= new Tournamenttest("hello");
io.saveTournament(tournament);
} }
} }

View File

@ -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) {
}
}

View File

@ -1,6 +1,8 @@
package ch.zhaw.projekt2.turnierverwaltung; package ch.zhaw.projekt2.turnierverwaltung;
public abstract class Tournament { import java.io.Serializable;
public abstract class Tournament implements Serializable {
private String name; private String name;
public Tournament(String name){ public Tournament(String name){