码迷,mamicode.com
首页 > 其他好文 > 详细

后缀名为properties,config和xml的文件内容读取

时间:2016-09-20 21:25:20      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

1、先建立文件(后缀名为properties和config)

2、读取类建立

public class Read{

  public static Properties  properties = new Properties();

  static {

    tr{

      properties.load(new FileReader(src/type.properties));

    }catch(Exception e){

      e.printStackTrace();

    }

  }

  public static void main(String[] args){

    //方式一

    String type = properties.getProperty("type");

    TVFactory tvFactory = (TVFactory)Class.forName(type).newInstance();

    TV tv = tvFactory.produceTV();

    tv.pay();

    //方式二(xml的读取)

    SAXReader reader = new SAXReader();

    Document document = reader.read(new File(src/tv.xml));

    Element config = document.getRootElement();

    Iterator it =  config.elementIterator();

    String str = null;

    while(it.hasNext){

      Element type = it.next();

      str = type.getStringValue();

    }

         TVFactory tvFactory = (TVFactory)Class.forName(type).newInstance();

    TV tv = tvFactory.produceTV();

    tv.pay();

  }

}

后缀名为properties,config和xml的文件内容读取

标签:

原文地址:http://www.cnblogs.com/hgc-bky/p/5890371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!