1******************************* TXT file platform.txt
{"SLS": {
"Domobkey", "123456",
"Signpassword": "sls_api_20190914",
"Qqcoinskey": "sls_api_20190914"
}, "Zonggou": {
"Domobkey", "123456",
"Signpassword": "sls_api_20190914",
"Qqcoinskey": "sls_api_20190914"
}, "Zhihui": {
"Domobkey", "123456",
"Signpassword": "sls_api_20190914",
"Qqcoinskey": "sls_api_20190914"
}
}
2 *************************** Platform.java File
Package Com.weixin.pojo;
Import java.io.Serializable;
public class Platform implements Serializable {
/**
*
*/
Private static final long serialversionuid = 3987351091823568051L;
Private String Signpassword;
Private String Qqcoinskey;
Private String Domobkey;
Public String Getdomobkey () {
return domobkey;
}
public void Setdomobkey (String domobkey) {
This.domobkey = Domobkey;
}
Public String Getqqcoinskey () {
return qqcoinskey;
}
public void Setqqcoinskey (String qqcoinskey) {
This.qqcoinskey = Qqcoinskey;
}
Public String Getsignpassword () {
return Signpassword;
}
public void Setsignpassword (String signpassword) {
This.signpassword = Signpassword;
}
3 ************************platformutils.java File
Package Com.weixin.common;
Import Java.io.InputStream;
Import Java.util.HashMap;
Import Java.util.Map;
Import Java.util.Scanner;
Import Org.apache.logging.log4j.LogManager;
Import Org.apache.logging.log4j.Logger;
Import Com.google.common.reflect.TypeToken;
Import Com.weixin.pojo.Platform;
public class Platformutils {
Private static final map<string, platform> Map = new hashmap<string, platform> ();
Protected static final Logger log = Logmanager
. GetLogger (Platformutils.class);
public static Platform Read (String Platform) {
return Map.get (platform);
}
static {
try {
InputStream is = PlatformUtils.class.getClassLoader ()
. getResourceAsStream ("Platform.txt");
StringBuilder sb = new StringBuilder ();
Scanner Scanner = new Scanner (IS);
while (Scanner.hasnext ()) {
Sb.append (Scanner.next ());
}
map<string, platform> result = Commonutil.gson (). Fromjson (
Sb.tostring (), New typetoken<map<string, platform>> () {
Private static final long serialversionuid = 3475626220958000879L;
}.gettype ());
Map.putall (result);
Scanner.close ();
} catch (Exception e) {
Log.error ("read error {}", E);
}
}
}
Save the configuration file in a JSON string format and read it into a map