Save the configuration file in a JSON string format and read it into a map

Source: Internet
Author: User



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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.