-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenuFile.java
85 lines (74 loc) · 2.01 KB
/
MainMenuFile.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class MainMenuFile {
/**
* String FILENAME is for reading and writing from the Menu database
*/
private static final String FILENAME = "Menu.txt";
/**
* Read into a File
*/
public static void readAll(MainMenu Menu) {
try {
File myObj = new File(FILENAME);
if (myObj.createNewFile()) {
System.out.println("File created: " + myObj.getName());
}
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
try {
FileInputStream F = new FileInputStream(FILENAME);
ObjectInputStream S = new ObjectInputStream(F);
Menu.readObject(S);
S.close();
F.close();
} catch (NullPointerException E) {
System.out.println("Reading Done");
E.printStackTrace();
} catch (FileNotFoundException E) {
System.out.println("File not found error");
} catch (IOException I) {
// System.out.println("File not closed error");
// I.printStackTrace();
} catch (ClassNotFoundException I) {
System.out.println("Class not found");
I.printStackTrace();
}
}
/**
* Write into a File
*/
public static void writeAll(MainMenu Menu) {
try {
File myObj = new File(FILENAME);
if (myObj.createNewFile()) {
System.out.println("File created: " + myObj.getName());
}
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
try {
FileOutputStream F = new FileOutputStream(FILENAME);
ObjectOutputStream S = new ObjectOutputStream(F);
Menu.writeObject(S);
S.close();
F.close();
} catch (NullPointerException E) {
System.out.println("Writting Done");
E.printStackTrace();
} catch (FileNotFoundException E) {
System.out.println("File not found error");
} catch (IOException I) {
System.out.println("File not closed error");
I.printStackTrace();
}
}
}