zoukankan      html  css  js  c++  java
  • Java库使用----xstream1.3.1

    package com.xstream;
    
    import java.util.Map;
    
    /**
     * XStream可以自动生成相关的xml配置
     */
    public class XstreamTest
    {
        private String moduleName;
    
        private Map<String, String> env;
    
        public String getModuleName()
        {
            return moduleName;
        }
    
        public void setModuleName(String moduleName)
        {
            this.moduleName = moduleName;
        }
    
        public Map<String, String> getEnv()
        {
            return env;
        }
    
        public void setEnv(Map<String, String> env)
        {
            this.env = env;
        }
    
    }
    

      

    <com.xstream.XstreamTest-array>
      <com.xstream.XstreamTest>
        <moduleName>moduleName</moduleName>
        <env class="tree-map">
          <no-comparator/>
          <entry>
            <string>aa</string>
            <string>bb</string>
          </entry>
          <entry>
            <string>cc</string>
            <string>dd</string>
          </entry>
        </env>
      </com.xstream.XstreamTest>
    </com.xstream.XstreamTest-array>
    

      

    package com.xstream;
    
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    
    import com.thoughtworks.xstream.XStream;
    import com.thoughtworks.xstream.io.xml.DomDriver;
    
    /**
     * @author guoxm
     * @version 创建时间:2015-9-16 下午08:23:54
     */
    public class MainTest
    {
        public static void main(String[] args) throws FileNotFoundException
        {
            XStream xstream = new XStream(new DomDriver());
    
            File file = new File("src/test.xml");
            final FileInputStream fileInput = new FileInputStream(file);
            final BufferedInputStream br = new BufferedInputStream(fileInput);
    
            Object object = xstream.fromXML(br);
            
            if (object instanceof XstreamTest[])
            {
                XstreamTest[] xstreamObjects = (XstreamTest[]) object;
                for (XstreamTest xstreamTest : xstreamObjects)
                {
                    System.out.println(xstreamTest.getModuleName() + '
    '+ xstreamTest.getEnv().toString());
                }
            }
        }
    
    }
    

      

  • 相关阅读:
    hdu 1199 Color the Ball 离散线段树
    poj 2623 Sequence Median 堆的灵活运用
    hdu 2251 Dungeon Master bfs
    HDU 1166 敌兵布阵 线段树
    UVALive 4426 Blast the Enemy! 计算几何求重心
    UVALive 4425 Another Brick in the Wall 暴力
    UVALive 4423 String LD 暴力
    UVALive 4872 Underground Cables 最小生成树
    UVALive 4870 Roller Coaster 01背包
    UVALive 4869 Profits DP
  • 原文地址:https://www.cnblogs.com/wuxinliulei/p/4814404.html
Copyright © 2011-2022 走看看