📄 javalang.doc17.html
字号:
<html>
<head>
<title>The Java Language Specification The Package java.lang </title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
<a href="index.html">Contents</a> | <a href="javalang.doc16.html">Prev</a> | <a href="javalang.doc18.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
<a name="36485"></a>
<center><h1>20.18 The Class <code>java.lang.System</code></h1></center>
<a name="5969"></a>
The <code>System</code> class contains a number of useful class variables and class methods.
It cannot be instantiated. Among the facilities provided by the <code>System</code> class are
standard input, output, and error output streams; access to externally defined
"properties"; a means of loading files and libraries; and a utility method for
quickly copying a portion of an array.
<p><pre><a name="14129"></a>public final class <code><b>System</b></code> {
<a name="3162"></a> public static InputStream <code><b>in</b></code>;
<a name="3163"></a> public static PrintStream <code><b>out</b></code>;
<a name="3164"></a> public static PrintStream <code><b>err</b></code>;
<a name="3199"></a> public static SecurityManager <code><b>getSecurityManager</b></code>();
<a name="3165"></a> public static void <code><b>setSecurityManager</b></code>(SecurityManager s)
<a name="6441"></a> throws SecurityException;
<a name="3167"></a> public static long <code><b>currentTimeMillis</b></code>();
<a name="3172"></a> public static Properties <code><b>getProperties</b></code>()
<a name="6410"></a> throws SecurityException;
<a name="6412"></a> public static void <code><b>setProperties</b></code>(Properties props)
<a name="3173"></a> throws SecurityException;
<a name="6417"></a> public static String <code><b>getProperty</b></code>(String key)
<a name="5957"></a> throws SecurityException;
<a name="6422"></a> public static String <code><b>getProperty</b></code>(String key, String defaults)
<a name="5958"></a> throws SecurityException;
<a name="6427"></a> public static void <code><b>exit</b></code>(int status) throws SecurityException;
<a name="3176"></a> public static void <code><b>gc</b></code>();
<a name="3177"></a> public static void <code><b>runFinalization</b></code>();
<a name="6432"></a> public static void <code><b>load</b></code>(String filename)
<a name="3178"></a> throws SecurityException, UnsatisfiedLinkError;
<a name="6437"></a> public static void <code><b>loadLibrary</b></code>(String libname)
<a name="3179"></a> throws SecurityException, UnsatisfiedLinkError;
<a name="3189"></a> public static void <code><b>arraycopy</b></code>(Object src, int srcOffset,
<a name="3193"></a> Object dst, int dstOffset, int length)<br>
throws NullPointerException,
<a name="6408"></a> ArrayStoreException, IndexOutOfBoundsException;
<a name="3187"></a>}
</pre><a name="14130"></a>
<p><font size=+1><strong>20.18.1 </strong> <code>public static InputStream <code><b>in</b></code>;</code></font>
<p>
<a name="6343"></a>
The initial value of this variable is a "standard" input stream, already open and
ready to supply input data. Typically, this corresponds to keyboard input or
another input source specified by the host environment or user. Note that this field
is not <code>final</code>, so its value may be updated if necessary.
<p><a name="14131"></a>
<p><font size=+1><strong>20.18.2 </strong> <code>public static PrintStream <code><b>out</b></code>;</code></font>
<p>
<a name="6348"></a>
The initial value of this variable is a "standard" output stream, already open and
ready to accept output data. Typically, this corresponds to display output or
another output destination specified by the host environment or user. Note that this
field is not <code>final</code>, so its value may be updated if necessary.
<p><a name="6360"></a>
For simple Java applications, a typical way to write a line of output data is:<p>
<pre><a name="6361"></a>System.out.println(data)
</pre><a name="6362"></a>
See the <code>println</code> method of class <code>PrintStream</code> <a href="javaio.doc20.html#29906">(§22.22)</a>.<p>
<a name="14132"></a>
<p><font size=+1><strong>20.18.3 </strong> <code>public static PrintStream <code><b>err</b></code>;</code></font>
<p>
<a name="6368"></a>
The initial value of this variable is a "standard" error output stream, already open
and ready to accept output data. Typically, this corresponds to display output or
another output destination specified by the host environment or user. By convention,
this output stream is used to display error messages or other information that
should come to the immediate attention of a user even if the principal output
stream, the value of the variable <code>out</code>, has been redirected to a file or other destination
that is typically not continuously monitored. Note that this field is not <code>final</code>,
so its value may be updated if necessary.
<p><a name="3205"></a>
<p><font size=+1><strong>20.18.4 </strong> <code>public static SecurityManager <code><b>getSecurityManager</b></code>()</code></font>
<p>
<a name="5970"></a>
If a security manager has already been established for the currently running Java
system, a reference to that security manager is returned. Otherwise, <code>null</code> is
returned.
<p><a name="14133"></a>
<p><font size=+1><strong>20.18.5 </strong> <code>public static void <code><b>setSecurityManager</b></code>(SecurityManager s)<br>throws SecurityException</code></font>
<p>
<a name="5972"></a>
If a security manager has already been established for the currently running Java
system, a <code>SecurityException</code> is thrown. Otherwise, the argument is established
as the current security manager. If the argument is <code>null</code> and no security manager
has been established, then no action is taken and the method simply returns normally.
<p><a name="5984"></a>
<p><font size=+1><strong>20.18.6 </strong> <code>public static long <code><b>currentTimeMillis</b></code>()</code></font>
<p>
<a name="6012"></a>
Returns the difference, measured in milliseconds, between the current time and
the standard base time known as "the epoch," 00:00:00 GMT on January 1, 1970.
See the description of the class <code>Date</code> <a href="javautil.doc2.html#7433">(§21.3)</a> for a discussion of slight discrepancies
that may arise between "computer time" and UTC (Coordinated Universal
Time).
<p><a name="6014"></a>
<p><font size=+1><strong>20.18.7 </strong> <code>public static Properties <code><b>getProperties</b></code>()<br>throws SecurityException</code></font>
<p>
<a name="6372"></a>
First, if there is a security manager, its <code>checkPropertiesAccess</code> method
<a href="javalang.doc16.html#29869">(§20.17.15)</a> is called with no arguments.
<p><a name="6473"></a>
The current set of system properties for use by the <code>getProperty</code> method is returned as a Properties object <a href="javautil.doc5.html#23061">(§21.6)</a>. If there is no current set of system properties, a set of system properties is first created and initialized. This set of system properties always includes values for the following keys:<p>
<pre><a name="6554"></a><i>Key Description of associated value
</i><a name="6513"></a>java.version Java version number
<a name="6514"></a>java.vendor Java-vendor-specific string
<a name="6515"></a>java.vendor.url Java vendor URL
<a name="6516"></a>java.home Java installation directory
<a name="6517"></a>java.class.version Java class format version number
<a name="6518"></a>java.class.path Java classpath
<a name="6519"></a>os.name Operating system name
<a name="6520"></a>os.arch Operating system architecture
<a name="6521"></a>os.version Operating system version
<a name="6522"></a>file.separator File separator (<code>/</code> on UNIX)
<a name="6523"></a>path.separator Path separator (<code>:</code> on UNIX)
<a name="6524"></a>line.separator Line separator (<code>\n</code> on UNIX)
<a name="6525"></a>user.name User account name
<a name="6526"></a>user.home User home directory
<a name="6527"></a>user.dir User's current working directory
</pre><a name="6626"></a>
Note that even if the security manager does not permit the <code>getProperties</code> operation, it may choose to permit the <code>getProperty</code> operation (§20.18.9)</a>.<p>
<a name="5986"></a>
<p><font size=+1><strong>20.18.8 </strong> <code>public static void <code><b>setProperties</b></code>(Properties props)<br>throws SecurityException</code></font>
<p>
<a name="6383"></a>
First, if there is a security manager, its <code>checkPropertiesAccess</code> method
<a href="javalang.doc16.html#29869">(§20.17.15)</a> is called with no arguments.
<p><a name="6470"></a>
The argument becomes the current set of system properties for use by the <code>getProperty</code> method. See the class <code>Properties</code> <a href="javautil.doc5.html#23061">(§21.6)</a>. If the argument is <code>null</code>, then the current set of system properties is forgotten.<p>
<a name="5965"></a>
<p><font size=+1><strong>20.18.9 </strong> <code>public static String <code><b>getProperty</b></code>(String key)<br>throws SecurityException</code></font>
<p>
<a name="6390"></a>
First, if there is a security manager, its <code>checkPropertyAccess</code> method
<a href="javalang.doc16.html#29883">(§20.17.16)</a> is called with the <code>key</code> as its argument.
<p><a name="6501"></a>
If there is no current set of system properties, a set of system properties is first created and initialized in the same manner as for the <code>getProperties</code> method <a href="javalang.doc17.html#6014">(§20.18.7)</a>.<p>
<a name="6542"></a>
The system property value associated with the specified <code>key</code> string is returned. If there is no property with that key, then <code>null</code> is returned.<p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -