In recent times, YAML has been touched, and as a serialized language, Yaml's readability seems to be easier to understand than XML, and more lightweight than CSV. At present, Yaml as a project automation framework of a data configuration file, in the use of the process by a certain praise ~ The following summarizes the experience in the actual use.
The style of Yaml:
How to use Yaml:
1 PrivateString Yamlfile;2 3 PrivateHashmap<string, Hashmap<string, string>>ml;4 5 /**6 * @function Constructors7 */8 PublicYamlutil () {9Yamlfile = "Test";Ten This. Getyamlfile (); One } A - /** - * @function loading Yaml files the */ -@SuppressWarnings ("Unchecked") - Public voidGetyamlfile () { - +File f =NewFile ("test/" + Yamlfile + ". Yaml"); - Try { +ml = Yaml.loadtype (NewFileInputStream (F.getabsolutepath ()), HashMap.class); A}Catch(FileNotFoundException e) { at e.printstacktrace (); - } - } - - /** - * @function Obtain the corresponding keyword information in the Yaml file in * @paramkeyword - * @return to */ + PublicMap<string,string>getkeywordinfos (String keyword) { - thehashmap<string,string> map =NewHashmap<string,string>(); *Map =ml.get (keyword); $ returnmap;Panax Notoginseng } -}
Yaml encounters a small pit:
1. Note the full half of the colon .... It's not much to say.
2. Key value cannot be a full number
Test.yaml:
33033: name:driver Age :24
In this case, the result obtained when using ml.get (keyword) is null
3, the encoding format problem, if use Chinese please use UTF-8, cannot think Utf-8-bom format.
This style, when used in ml.get (keyword), also gets the same result as null.
/*** @function get the corresponding keyword information in the yaml file *@paramkeyword *@return */ PublicMap<string,string>getkeywordinfos (String keyword) {HashMap<String,String> map =NewHashmap<string,string>(); for(String key:ml.keySet ()) {System.out.println (Key.charat (0)); if(key.equals (keyword)) {map=ml.get (keyword); } } returnmap; }
In the execution of key.equals (keyword), key is Father,keyword is also father but the actual result is false, further analysis found that key and keyword hashcode is not equal, Key.charat ( 0) The value is "", then a bit of a circle. Get the first 3 bytes of key discovery results as follows, which is a representation of UTF-8. Finally try to find is utf-8-bom in mischief.
Above is I in the use of the process encountered problems, in this, again thanks to fly the sum of children.
Yaml Usage Tips