java读取YAML文件

loadString:
  type:link
  locater:kw  
rootLocation: root
timeout: 15

 

package com.test;

import org.ho.yaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import org.testng.Assert;



public class Test2 {

    /**
     * @param args
     */
    
    public void getTest() {
        Assert.assertEquals(1,2);
        System.out.println("1234");
    }
    
    public void getYamlFile() throws FileNotFoundException{    
        File f = new File("src/com/test/Test2.yaml");
        System.out.println(f.getAbsolutePath());
        HashMap ml = Yaml.loadType(new FileInputStream(f.getAbsolutePath()), HashMap.class);
        System.out.println(ml.size());        
        System.out.println(((HashMap) ml.get("loadString")).get("locater"));        
    }
    public static void main(String[] args) throws FileNotFoundException {
        Test2 t = new Test2();        
        t.getYamlFile();
    }

}

posted on 2012-10-07 21:28  张飞_  阅读(11219)  评论(5编辑  收藏  举报

导航