-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.java
More file actions
39 lines (34 loc) · 1.43 KB
/
FileManager.java
File metadata and controls
39 lines (34 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;
import java.util.ArrayList;
public class FileManager {
private static final String MATCH_FILE = "matches.ser";
private static final String TEAM_FILE = "teams.ser";
public static void saveMatches(ArrayList<Match> matches) {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(MATCH_FILE))) {
oos.writeObject(matches);
} catch (IOException e) {
System.out.println("Error saving match history: " + e.getMessage());
}
}
public static ArrayList<Match> loadMatches() {
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(MATCH_FILE))) {
return (ArrayList<Match>) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
return new ArrayList<>();
}
}
public static void saveTeams(ArrayList<Team> teams) {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(TEAM_FILE))) {
oos.writeObject(teams);
} catch (IOException e) {
System.out.println("Error saving teams: " + e.getMessage());
}
}
public static ArrayList<Team> loadTeams() {
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(TEAM_FILE))) {
return (ArrayList<Team>) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
return new ArrayList<>();
}
}
}