zoukankan      html  css  js  c++  java
  • 后缀名为properties,config和xml的文件内容读取

    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();

      }

    }

  • 相关阅读:
    1082 射击比赛 (20 分)
    1091 N-自守数 (15 分)
    1064 朋友数 (20 分)
    1031 查验身份证 (15 分)
    1028 人口普查 (20 分)
    1059 C语言竞赛 (20 分)
    1083 是否存在相等的差 (20 分)
    1077 互评成绩计算 (20 分)
    792. 高精度减法
    791. 高精度加法
  • 原文地址:https://www.cnblogs.com/hgc-bky/p/5890371.html
Copyright © 2011-2022 走看看