forked from pet1100/Koebmand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage.java
57 lines (46 loc) · 1.02 KB
/
Storage.java
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Package Koebmand;
public class Storage
{
String filename = "StorageData";
ArrayList<Goods> allGoods = new ArrayList<Goods>();
Storage()
{
allGoods = loadStorage();
}
private loadStorage()
{
ArrayList<Goods> goodsList = new ArrayList<Goods>();
try {
FileInputStream fileIn = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(fileIn);
try {
goodsList = (ArrayList<Goods>) in.readObject();
}
catch (Exception e) {
}
in.close();
fileIn.close();
}
catch (IOException i) {
}
return goodsList;
}
private saveStorage()
{
FileOutputStream fileOut = null;
ObjectOutputStream out = null;
try {
File storagefile = new File(filename);
storagefile.createNewFile();
fileOut = new FileOutputStream(filename, false);
out = new ObjectOutputStream(fileOut);
out.writeObject(movies);
out.close();
fileOut.close();
System.out.println("Succes");
}
catch (Exception e) {
System.out.println("Failed saving");
}
}
}