-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.java
More file actions
68 lines (60 loc) · 2.02 KB
/
Copy pathFileManager.java
File metadata and controls
68 lines (60 loc) · 2.02 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.File;
import java.io.FileInputStream;
/**
*
* @author Baqir 4.0.2
*/
public class FileManager {
static class FileNames {
static String HOME = "home.txt";
static String HISTORY = "history.txt";
static String FAVORITIES = "favorities.txt";
static String FIREWALL = "firewall.txt";
static String ENABLE_FIREWALL_CHECK = "fcheck.txt";
}
private static String DEFAULT_HOME_URL = "http://rizavi.yolasite.com/";
public static void initFiles()
{
if(!new File(FileNames.HOME).exists() || !new File(FileNames.HISTORY).exists() || !new File(FileNames.FAVORITIES).exists()
|| !new File(FileNames.FIREWALL).exists() || !new File(FileNames.ENABLE_FIREWALL_CHECK).exists())
{
boolean c = true;
writeIn(FileNames.HOME, DEFAULT_HOME_URL);
writeIn(FileNames.HISTORY, null);
writeIn(FileNames.FAVORITIES, null);
writeIn(FileNames.FIREWALL, null);
writeIn(FileNames.ENABLE_FIREWALL_CHECK, c);
}
}
public static void writeIn(String name, Object o)
{
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(name)));
oos.writeObject(o);
oos.close();
}
catch (IOException e){
e.printStackTrace();
}
}
public static Object readFrom(String name)
{
Object temp = null;
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File(name)));
temp = ois.readObject();
ois.close();
}
catch (IOException e){
e.printStackTrace();
}
catch (ClassNotFoundException e){
e.printStackTrace();
}
return temp;
}
}