-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSaving.java
More file actions
51 lines (50 loc) · 1.58 KB
/
Copy pathFileSaving.java
File metadata and controls
51 lines (50 loc) · 1.58 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
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.*;
public class FileSaving
{
public static void save(String DateiName, Object[] objects)
{
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream
((new File("Spielstaende").getAbsolutePath()) + "/" + (DateiName+".bin") )))
{
for(Object e : objects)
out.writeObject(e);
} catch (Exception e) {
System.out.println("Serialization failed");
System.out.println(e);
}
}
public static Object[] load(String DateiName, int laenge) {
Object[] o = new Object[laenge];
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream
((new File("Spielstaende").getAbsolutePath()) + "/" + (DateiName+".bin") )))
{
for (int i = 0; i < o.length; i++)
{
o[i] = (Object) in.readObject();
}
Spiel.konsole.printD("System",8);
} catch (Exception e) {
System.out.println(e);
System.out.println("Deserialization failed");
System.out.println();
}
return o;
}
public static boolean WorldsaveExists(String DateiName)
{
File f = new File(new File("Spielstaende").getAbsolutePath() + "/" + (DateiName+".bin") );
if(f.exists() && !f.isDirectory() )
{
return true;
}
return false;
}
public static boolean saveIsEmpty()
{
if(0 >= new File("Spielstaende").listFiles().length)
{
return true;
}
return false;
}
}