-
Notifications
You must be signed in to change notification settings - Fork 0
/
Save.java
38 lines (33 loc) · 1.14 KB
/
Save.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
import java.io.*;
public class Save {
public void save(General ... generals){
try {
FileOutputStream file = new FileOutputStream("zapis.txt");
ObjectOutputStream object = new ObjectOutputStream(file);
for (General i : generals) {
object.writeObject(i);
}
object.close();
file.close();
} catch (FileNotFoundException e){
System.out.println("nie znaleziono pliku");
} catch (IOException e) {
e.printStackTrace();
}
}
public void readFromFIle(General ...generals){
try{
FileInputStream file = new FileInputStream("zapis.txt");
ObjectInputStream object = new ObjectInputStream(file);
for(General i : generals){
i = (General) object.readObject();
}
file.close();
object.close();
} catch (FileNotFoundException e){
System.out.println("nie znaleziono pliku");
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
}
}