-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddressConfig.java
70 lines (60 loc) · 1.94 KB
/
AddressConfig.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
package edu.nctu.wirelab.testsignalv1;
import android.util.Log;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class AddressConfig {
private static final String TagName = "AddressConfig";
public static String myUserName = null;
public static void SetUserName(String username){
myUserName = username;
}
public static void SaveConfigTo(String path){
//Log.d(TagName, "SaveConfigTo: " + path);
try {
BufferedWriter out = new BufferedWriter(new FileWriter(path));
out.write("username="+myUserName);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean LoadConfigFrom(String path){
//Log.d(TagName, "LoadConfigFrom: " + path);
File file = new File(path);
int flag = 0;
if(!file.exists()){
return false;
}
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
Log.d(TagName, "line:"+line);
String[] token = line.split("=");
if( token[0].equals("username") && token.length>=2 ){
//Log.d(TagName, "token[0].equals(\"email\")");
myUserName = token[1];
flag = 1;
//Log.d(TagName, "myEmail:"+myEmail);
}
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if( flag==1 ) {
return true;
}
else{
Log.d(TagName, "lack of email in the config");
return false;
}
}
}