-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRead.java
More file actions
97 lines (84 loc) · 2.36 KB
/
Read.java
File metadata and controls
97 lines (84 loc) · 2.36 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @(#)Read.java
*
*
* @author
* @version 1.00 2010/3/7
*/
package backup;
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;
public class Read {
private HashMap hm = readMap();
public static String path = System.getProperty("user.dir")+File.separator+"bin"+File.separator+"backup.prop";
HashMap getMap(){
hm = readMap();
return hm;
}
Map setMap(Map m){
if(m != null && m instanceof HashMap){
HashMap old = hm;
hm = (HashMap)m;
saveMap();
return old;
}
return null;
}
private void saveMap(){
try{
ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(path)));
os.writeObject(hm);
os.flush();
os.close();
}
catch(Exception er){
System.out.print(er);
}
}
private HashMap readMap(){
try{
checkFile();
ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(new FileInputStream(path)));
Object n = is.readObject();
// System.out.println(n);
if(n != null && n instanceof HashMap){
hm = (HashMap)n;
// System.out.println("not null and hashmap");
}
else{
hm = null;
}
is.close( );
}catch(Exception er){
System.out.print(er);
}
// System.out.println("read map "+hm);
return hm;
}
private void checkFile() throws Exception{
File f = new File(path);
if(!f.exists()){
JOptionPane.showMessageDialog(null,"Error in Program initializing settings...(default loaded)\nsettings will be change to defaul values... but System may not be function Properly..!!!!\n\nContact System Administrator \nRef.Code: backup.prop0013","Error in initializing settings...",JOptionPane.ERROR_MESSAGE);
new FileWriter(path);
HashMap hm1 = new HashMap();
hm1.put("sql_bakup_exe","bin\\mysqldump.exe");
hm1.put("sql_backup_path","");
hm1.put("sql_db_port","3306");
hm1.put("sql_db_root","localhost");
hm1.put("sql_db_name","database");
hm1.put("sql_db_user","root");
hm1.put("sql_db_pass","");
hm1.put("sql_db_auto","false");
hm1.put("sql_db_auto_method","1");
setMap(hm1);
}
}
public void checkInit(){
try{
checkFile();
}
catch(Exception er){
}
}
}