-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJogoIO.java
50 lines (44 loc) · 933 Bytes
/
JogoIO.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
import java.io.*;
class JogoIO
{
private Jogo j;
public JogoIO(){}
public JogoIO(Jogo j){this.j=j;}
public void save(String fname)
{
try
{
FileOutputStream fos=new FileOutputStream(fname);
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(j);
oos.close();
}
catch(IOException e)
{
System.out.println("Ocorreu um problema ao usar o ficheiro");
System.out.println(e);
}
}
public Jogo load(String fname)
{
Jogo j=null;
try
{
FileInputStream fos=new FileInputStream(fname);
ObjectInputStream oos=new ObjectInputStream(fos);
j=(Jogo)(oos.readObject());
oos.close();
}
catch(IOException e)
{
System.out.println("Ocorreu um problema ao usar o ficheiro");
System.out.println(e);
}
catch(Exception ex)
{
System.out.println("Ocorreu um problema inesperado ao tentar abrir o ficheiro");
System.out.println(ex);
}
return(j);
}
}