📄 javalang.doc15.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.doc14.html">Prev</a> | <a href="javalang.doc16.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
<a name="2637"></a>
<center><h1>20.16 The Class <code>java.lang.Runtime</code></h1></center>
<pre><a name="14077"></a>public class <code><b>Runtime</b></code> {
<a name="3097"></a> public static Runtime <code><b>getRuntime</b></code>();
<a name="3098"></a> public void <code><b>exit</b></code>(int status) throws SecurityException;
<a name="52509"></a> public Process <code><b>exec</b></code>(String command) throws<br>
IOException,SecurityException,IndexOutOfBoundsException;
<a name="52510"></a> public Process <code><b>exec</b></code>(String command, String envp[]) throws<br>
IOException,SecurityException,IndexOutOfBoundsException;
<a name="3101"></a> public Process <code><b>exec</b></code>(String cmdarray[]) throws<br>
IOException,SecurityException,IndexOutOfBoundsException;
<a name="52499"></a> public Process <code><b>exec</b></code>(String cmdarray[], String envp[]) throws<br>
IOException,SecurityException,IndexOutOfBoundsException;
<a name="52500"></a> public long <code><b>totalMemory</b></code>();
<a name="3103"></a> public long <code><b>freeMemory</b></code>();
<a name="3105"></a> public void <code><b>gc</b></code>();
<a name="3106"></a> public void <code><b>runFinalization</b></code>();
<a name="3107"></a> public void <code><b>traceInstructions</b></code>(boolean on);
<a name="3108"></a> public void <code><b>traceMethodCalls</b></code>(boolean on);
<a name="3109"></a> public void <code><b>load</b></code>(String filename)
<a name="6938"></a> throws SecurityException, UnsatisfiedLinkError;
<a name="6940"></a> public void <code><b>loadLibrary</b></code>(String libname)
<a name="3110"></a> throws SecurityException, UnsatisfiedLinkError;
<a name="3111"></a> public InputStream <code><b>getLocalizedInputStream</b></code>(InputStream in);
<a name="3112"></a> public OutputStream<br>
<code><b> getLocalizedOutputStream</b></code>(OutputStream out);
<a name="3115"></a>}
</pre><a name="14078"></a>
<p><font size=+1><strong>20.16.1 </strong> <code>public static Runtime <code><b>getRuntime</b></code>()</code></font>
<p>
<a name="7034"></a>
This method returns the current <code>Runtime</code> object. Most of the methods of class
<code>Runtime</code> are instance methods and must be invoked with respect to the current
runtime object.
<p><a name="34351"></a>
<p><font size=+1><strong>20.16.2 </strong> <code>public void <code><b>exit</b></code>(int status)<br>throws SecurityException</code></font>
<p>
<a name="34355"></a>
First, if there is a security manager, its <code>checkExit</code> method <a href="javalang.doc16.html#14111">(§20.17.13)</a> is called
with the <code>status</code> value as its argument.
<p><a name="6738"></a>
This method terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.<p>
<a name="6739"></a>
This method never returns normally.<p>
<a name="7384"></a>
See also the method <code>exit</code> <a href="javalang.doc17.html#14142">(§20.18.11)</a> of class <code>System</code>, which is the conventional and convenient means of invoking this method.<p>
<a name="14080"></a>
<p><font size=+1><strong>20.16.3 </strong> <code>public Process <code><b>exec</b></code>(String command)<br>throws IOException, SecurityException,<br>      IndexOutOfBoundsException</code></font>
<p>
<a name="6779"></a>
The <code>command</code> argument is parsed into tokens and then executed as a command in a
separate process. The token parsing is done by a <code>StringTokenizer</code> <a href="javautil.doc8.html#7648">(§21.10)</a> created
by the call:
<p><pre><a name="25768"></a>new StringTokenizer(command)
</pre><a name="25769"></a>
with no further modification of the character categories.
<p><a name="6833"></a>
This method behaves exactly as if it performs the call:<p>
<pre><a name="30749"></a><code>exec(command, null)
</code></pre><a name="30750"></a>
See <a href="javalang.doc15.html#14082">§20.16.4</a>.
<p><a name="14082"></a>
<p><font size=+1><strong>20.16.4 </strong> <code>public Process <code><b>exec</b></code>(String command, String envp[])<br>throws IOException, SecurityException,<br>        IndexOutOfBoundsException</code></font>
<p>
<a name="25777"></a>
The <code>command</code> argument is parsed into tokens and then executed as a command in a
separate process with an environment specified by <code>envp</code>. The token parsing is
done by a <code>StringTokenizer</code> <a href="javautil.doc8.html#7648">(§21.10)</a> created by the call:
<p><pre><a name="25778"></a>new StringTokenizer(command)
</pre><a name="25779"></a>
with no further modification of the character categories.
<p><a name="30754"></a>
This method breaks the <code>command</code> string into tokens and creates a new array <code>cmdarray</code> containing the tokens in the order that they were produced by the string tokenizer; it then behaves exactly as if it performs the call:<p>
<pre><a name="30758"></a><code>exec(cmdarray, envp)
</code></pre><a name="30760"></a>
See <a href="javalang.doc15.html#6806">§20.16.6</a>.
<p><a name="30759"></a>
<p><font size=+1><strong>20.16.5 </strong> <code>public Process <code><b>exec</b></code>(String cmdarray[])<br>throws IOException, SecurityException,<br>      NullPointerException, IndexOutOfBoundsException</code></font>
<p>
<a name="6843"></a>
The command specified by the tokens in <code>cmdarray</code> is executed as a command in a
separate process.
<p><a name="6765"></a>
This method behaves exactly as if it performs the call:<p>
<pre><a name="30762"></a><code>exec(cmdarray, null)
</code></pre><a name="30763"></a>
See <a href="javalang.doc15.html#6806">§20.16.6</a>.
<p><a name="6806"></a>
<p><font size=+1><strong>20.16.6 </strong> <code>public Process <code><b>exec</b></code>(String cmdarray[], String envp[])<br>throws IOException, SecurityException,<br>      NullPointerException, IndexOutOfBoundsException</code></font>
<p>
<a name="6810"></a>
First, if there is a security manager, its <code>checkExec</code> method <a href="javalang.doc16.html#14112">(§20.17.14)</a> is called
with the first component of the array <code>cmdarray</code> as its argument.
<p><a name="25764"></a>
If <code>cmdarray</code> is <code>null</code>, a <code>NullPointerException</code> is thrown. If <code>cmdarray</code> is an empty array (has length <code>0</code>), an <code>IndexOutOfBoundsException</code> is thrown.<p>
<a name="6782"></a>
Given an array of strings <code>cmdarray</code>, representing the tokens of a command line, and an array of strings <code>envp</code>, representing an "environment" that defines system properties, this method creates a new process in which to execute the specified command and returns a <code>Process</code> object <a href="javalang.doc14.html#14463">(§20.15)</a> representing the new process.<p>
<a name="14089"></a>
<p><font size=+1><strong>20.16.7 </strong> <code>public long <code><b>totalMemory</b></code>()</code></font>
<p>
<a name="6848"></a>
The total amount of memory currently available for current and future created
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -