zoukankan      html  css  js  c++  java
  • [Java] Properties类

    java.util.Properties

    The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.

    A property list can contain another property list as its "defaults"; this second property list is searched if the property key is not found in the original property list.

    因为Properties继承自Hashtable(继承Dictionary,实现Map接口), put/putAll方法可以被使用.但不推荐,因为可能插入不是字符串类型的条目. 应该使用setProperties方法. 

    如果store和save方法被那些包含费字符串类型的key/value的"妥协"Properties对象, 调用会失败.类似的调用propertyName或者list方法也会失败.

    The load(Reader) / store(Writer, String) methods load and store properties from and to a character based stream in a simple line-oriented format specified below. The load(InputStream) / store(OutputStream, String) methods work the same way as the load(Reader)/store(Writer, String) pair, except the input/output stream is encoded in ISO 8859-1 character encoding. Characters that cannot be directly represented in this encoding can be written using Unicode escapes as defined in section 3.3 of The Java™ Language Specification; only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.

    The loadFromXML(InputStream) and storeToXML(OutputStream, String, String) methods load and store properties in a simple XML format. By default the UTF-8 character encoding is used, however a specific encoding may be specified if required. An XML properties document has the following DOCTYPE declaration:

     <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
     

    Note that the system URI (http://java.sun.com/dtd/properties.dtd) is not accessed when exporting or importing properties; it merely serves as a string to uniquely identify the DTD, which is:

        <?xml version="1.0" encoding="UTF-8"?>
    
        <!-- DTD for properties -->
    
        <!ELEMENT properties ( comment?, entry* ) >
    
        <!ATTLIST properties version CDATA #FIXED "1.0">
    
        <!ELEMENT comment (#PCDATA) >
    
        <!ELEMENT entry (#PCDATA) >
    
        <!ATTLIST entry key CDATA #REQUIRED>
     

    This class is thread-safe: multiple threads can share a single Properties object without the need for external synchronization.

    Since:
    JDK1.0
    宛如智障,暗藏锋芒
  • 相关阅读:
    调试windows service的OnStart事件.
    Windows 7 下 ORACLE10G安装方法
    汉字编码对照表(gb2312/Big5/GB2312)
    FastReport For Delphi7 通用安装方法
    Visual Studio 2008 不能更改安装目录的原因
    全国信息技术标准化技术委员会汉字内码扩展规范(GBK)
    字符编码详解及由来(UNICODE,UTF8,GBK)[转帖]
    淘宝收藏
    蛙蛙推荐:设计一个Tracing组件
    收藏:SYN 攻击原理以及防范技术
  • 原文地址:https://www.cnblogs.com/zienzir/p/9343805.html
Copyright © 2011-2022 走看看