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"));
  • 相关阅读:
    负数求余数 C 和 Matlab&Python 处理不一样
    [Matlab] 线性卷积&圆周卷积代码实现
    [Arduino] 驱动RC522 读取 UID例程
    [C++] Nested Radical Constant
    [Arduino] 学习总结小合集(更新ING)
    谐振电路的品质因素总结
    142. Linked List Cycle II
    664. Strange Printer
    188. Best Time to Buy and Sell Stock IV
    50. Pow(x, n)
  • 原文地址:https://www.cnblogs.com/tiancy/p/6018695.html
Copyright © 2011-2022 走看看