• 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"));
  • 相关阅读:
    Hive的mysql安装配置
    Linux下的MySQL安装
    Hive的安装与基础指令
    浅谈数据库和数据仓库
    Hive的学习之路(理论篇)
    Spring---bean的命名
    Spring---单例模式(Singleton)的6种实现
    Spring---加载配置文件的几种方法(org.springframework.beans.factory.BeanDefinitionStoreException)
    Spring---配置文件概述
    Spring---Bean生命周期
  • 原文地址:https://www.cnblogs.com/tiancy/p/6018695.html
Copyright © 2020-2023  润新知