properties.html

来自「j2se5-api-zh,java文档的中文版本」· HTML 代码 · 共 744 行 · 第 1/3 页

HTML
744
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc (build 1.5.0_03) on Wed Nov 02 09:51:09 CST 2005 --><META http-equiv="Content-Type" content="text/html; charset=gb2312"><TITLE>Properties (Java 2 Platform SE 5.0)</TITLE><META NAME="keywords" CONTENT="java.util.Properties class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){    parent.document.title="Properties (Java 2 Platform SE 5.0)";}</SCRIPT><NOSCRIPT></NOSCRIPT></HEAD><BODY BGCOLOR="white" onload="windowTitle();"><!-- ========= START OF TOP NAVBAR ======= --><A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="跳过导航链接"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">  <TR ALIGN="center" VALIGN="top">  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>概述</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>软件包</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>类</B></FONT>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/Properties.html"><FONT CLASS="NavBarFont1"><B>使用</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>树</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>已过时</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>索引</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>帮助</B></FONT></A>&nbsp;</TD>  </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup>&nbsp;2&nbsp;Platform<br>Standard&nbsp;Ed. 5.0</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">&nbsp;<A HREF="PriorityQueue.html" title="java.util 中的类"><B>上一个类</B></A>&nbsp;&nbsp;<A HREF="PropertyPermission.html" title="java.util 中的类"><B>下一个类</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">  <A HREF="../../index.html@java_2Futil_2FProperties.html" target="_top"><B>框架</B></A>  &nbsp;&nbsp;<A HREF="Properties.html" target="_top"><B>无框架</B></A>  &nbsp;&nbsp;<SCRIPT type="text/javascript">  <!--  if(window==top) {    document.writeln('<A HREF="../../allclasses-noframe.html"><B>所有类</B></A>');  }  //--></SCRIPT><NOSCRIPT>  <A HREF="../../allclasses-noframe.html"><B>所有类</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">  摘要:&nbsp;嵌套&nbsp;|&nbsp;<A HREF="#field_summary">字段</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">构造方法</A>&nbsp;|&nbsp;<A HREF="#method_summary">方法</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">详细信息:&nbsp;<A HREF="#field_detail">字段</A>&nbsp;|&nbsp;<A HREF="#constructor_detail">构造方法</A>&nbsp;|&nbsp;<A HREF="#method_detail">方法</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">java.util</FONT><BR>类 Properties</H2><PRE><A HREF="../lang/Object.html" title="java.lang 中的类">java.lang.Object</A>  <IMG SRC="../../resources/inherit.gif" ALT="继承者 "><A HREF="Dictionary.html" title="java.util 中的类">java.util.Dictionary</A>&lt;K,V&gt;      <IMG SRC="../../resources/inherit.gif" ALT="继承者 "><A HREF="Hashtable.html" title="java.util 中的类">java.util.Hashtable</A>&lt;<A HREF="../lang/Object.html" title="java.lang 中的类">Object</A>,<A HREF="../lang/Object.html" title="java.lang 中的类">Object</A>&gt;          <IMG SRC="../../resources/inherit.gif" ALT="继承者 "><B>java.util.Properties</B></PRE><DL><DT><B>所有已实现的接口:</B> <DD>java.io.Serializable, <A HREF="../lang/Cloneable.html" title="java.lang 中的接口">Cloneable</A>, <A HREF="Map.html" title="java.util 中的接口">Map</A>&lt;<A HREF="../lang/Object.html" title="java.lang 中的类">Object</A>,<A HREF="../lang/Object.html" title="java.lang 中的类">Object</A>&gt;</DD></DL><HR><DL><DT><PRE>public class <B>Properties</B><DT>extends <A HREF="Hashtable.html" title="java.util 中的类">Hashtable</A>&lt;<A HREF="../lang/Object.html" title="java.lang 中的类">Object</A>,<A HREF="../lang/Object.html" title="java.lang 中的类">Object</A>&gt;</DL></PRE><P><code>Properties</code> 类表示了一个持久的属性集。<code>Properties</code> 可保存在流中或从流中加载。属性列表中每个键及其对应值都是一个字符串。 <p>一个属性列表可包含另一个属性列表作为它的“默认值”;如果未能在原有的属性列表中搜索到属性键,则搜索第二个属性列表。 <p>因为 <code>Properties</code> 继承于 <code>Hashtable</code>,所以可对 <code>Properties</code> 对象应用 <code>put</code> 和 <code>putAll</code> 方法。但强烈反对使用这两个方法,因为它们允许调用方插入其键或值不是 <code>Strings</code> 的项。相反,应该使用 <code>setProperty</code> 方法。如果在“有危险”的 <code>Properties</code> 对象(即包含非 <code>String</code> 的键或值)上调用 <code>store</code> 或 <code>save</code> 方法,则该调用将失败。 <p> <a name="encoding"></a><p> <A HREF="Properties.html#load(java.io.InputStream)"><CODE>load</CODE></A> 和 <A HREF="Properties.html#store(java.io.OutputStream, java.lang.String)"><CODE>store</CODE></A> 方法按下面所指定的、简单的面向行的格式加载和存储属性。此格式使用 ISO 8859-1 字符编码。可以使用 <a href="../../../../../../../../java.sun.com/docs/books/jls/html/3.doc.html#100850">Unicode 转义符</a>来编写此编码中无法直接表示的字符;转义序列中只允许单个 'u' 字符。可使用 native2ascii 工具对属性文件和其他字符编码进行相互转换。<p><p> <A HREF="Properties.html#loadFromXML(java.io.InputStream)"><CODE>loadFromXML(InputStream)</CODE></A> 和 <A HREF="Properties.html#storeToXML(java.io.OutputStream, java.lang.String, java.lang.String)"><CODE>storeToXML(OutputStream, String, String)</CODE></A> 方法按简单的 XML 格式加载和存储属性。默认使用 UTF-8 字符编码,但如果需要,可以指定某种特定的编码。XML 属性文档具有以下 DOCTYPE 声明: <pre> &lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt; </pre>注意,导入或导出属性时<i>不</i> 访问系统 URI (http://java.sun.com/dtd/properties.dtd);该系统 URI 仅作为一个惟一标识 DTD 的字符串: <pre>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;    &lt;!-- DTD for properties --&gt;    &lt;!ELEMENT properties ( comment?, entry* ) &gt;    &lt;!ATTLIST properties version CDATA #FIXED "1.0"&gt;    &lt;!ELEMENT comment (#PCDATA) &gt;    &lt;!ELEMENT entry (#PCDATA) &gt;    &lt;!ATTLIST entry key CDATA #REQUIRED&gt; </pre><P><P><DL><DT><B>从以下版本开始:</B></DT>  <DD>JDK1.0</DD><DT><B>另请参见:</B><DD><a href="../../../tooldocs/solaris/native2ascii.html">native2ascii tool for Solaris</a>, <a href="../../../tooldocs/windows/native2ascii.html">native2ascii tool for Windows</a>, <A HREF="../../serialized-form.html#java.util.Properties">序列化表格</A></DL><HR><P><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>字段摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected &nbsp;<A HREF="Properties.html" title="java.util 中的类">Properties</A></CODE></FONT></TD><TD><CODE><B><A HREF="Properties.html#defaults">defaults</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;一个属性列表,包含属性列表中所有未找到值的键的默认值。</TD></TR></TABLE>&nbsp;<!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>构造方法摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="Properties.html#Properties()">Properties</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;创建一个无默认值的空属性列表。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="Properties.html#Properties(java.util.Properties)">Properties</A></B>(<A HREF="Properties.html" title="java.util 中的类">Properties</A>&nbsp;defaults)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;创建一个带有指定默认值的空属性列表。</TD></TR></TABLE>&nbsp;<!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>方法摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="../lang/String.html" title="java.lang 中的类">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="Properties.html#getProperty(java.lang.String)">getProperty</A></B>(<A HREF="../lang/String.html" title="java.lang 中的类">String</A>&nbsp;key)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用指定的键在此属性列表中搜索属性。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="../lang/String.html" title="java.lang 中的类">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="Properties.html#getProperty(java.lang.String, java.lang.String)">getProperty</A></B>(<A HREF="../lang/String.html" title="java.lang 中的类">String</A>&nbsp;key,            <A HREF="../lang/String.html" title="java.lang 中的类">String</A>&nbsp;defaultValue)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用指定的键在属性列表中搜索属性。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="Properties.html#list(java.io.PrintStream)">list</A></B>(java.io.PrintStream&nbsp;out)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;将属性列表输出到指定的输出流。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="Properties.html#list(java.io.PrintWriter)">list</A></B>(java.io.PrintWriter&nbsp;out)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;将属性列表输出到指定的输出流。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="Properties.html#load(java.io.InputStream)">load</A></B>(java.io.InputStream&nbsp;inStream)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从输入流中读取属性列表(键和元素对)。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="Properties.html#loadFromXML(java.io.InputStream)">loadFromXML</A></B>(java.io.InputStream&nbsp;in)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;将指定输入流中由 XML 文档所表示的所有属性加载到此属性表中。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="Enumeration.html" title="java.util 中的接口">Enumeration</A>&lt;?&gt;</CODE></FONT></TD>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?