zoukankan      html  css  js  c++  java
  • java分享第七天-01(Hashmap和Hashtable的区别&Property)

    一、Hashmap和Hashtable的区别

    1 主要:Hashtable线程安全,同步,效率相对低下

               HashMap线程不安全,非同步,效率相对高

    2 父类:Hashtable是Dictionary   HashMap是AbstractMap

    3 rull:Hashtable键与值不能为null

    HashMap键最多一个null,值可心多个null

    二  Property

    1 作用:读写资源配置文件

    2 键与值只能为字符串

    3 方法:

    setProperty(String key,String value)

    getProperty(String key)

    getProperty(String key,String defaultValue)

    后缀:properties

    store(OutputStream out,String coomments)

    store(Writer writer,String coomments)

    load(inputStream instream)

    load(Reader  reader)

    .xml

    storeToXml(OutputStream os,String coomments):UTF-8字符集

    storeToXml(OutputStream os,String coomments,String encoding)

    loadFromXML(inputStream in)

         /*运用Properties输出到文件*/
        public static void main(String[] args) throws FileNotFoundException, IOException {
        //创建对象
        Properties properties=new Properties();
        //存储
        properties.setProperty("driver", "oracle.jdbc.driver.OracleDriver");
        //存储到e:/others绝对路径 
        properties.store(new FileOutputStream(new File("e:/others/db.properties")), "db配置");
        properties.storeToXML(new FileOutputStream(new File("e:/others/db.xml")), "db配置");
        properties.load(new FileReader("e:/others/db.properties"));
        System.out.println(properties.getProperty("user","Lili"));
  • 相关阅读:
    ubuntu 安装 redis desktop manager
    ubuntu 升级内核
    Ubuntu 内核升级,导致无法正常启动
    spring mvc 上传文件,但是接收到文件后发现文件变大,且文件打不开(multipartfile)
    angular5 open modal
    POJ 1426 Find the Multiple(二维DP)
    POJ 3093 Margritas
    POJ 3260 The Fewest Coins
    POJ 1837 Balance(二维DP)
    POJ 1337 A Lazy Worker
  • 原文地址:https://www.cnblogs.com/tiancy/p/6018695.html
Copyright © 2011-2022 走看看