📄 javaio.doc13.html
字号:
<html>
<head>
<title>The Java Language Specification The Package java.io </title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
<a href="index.html">Contents</a> | <a href="javaio.doc12.html">Prev</a> | <a href="javaio.doc14.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
<a name="29399"></a>
<center><h1>22.15 The Class <code>java.io.OutputStream</code></h1></center>
<a name="33840"></a>
An output stream accepts output bytes and sends them to some sink.
<p><pre><a name="29400"></a>public abstract class <code><b>OutputStream</b></code> {
<a name="29401"></a> public abstract void <code><b>write</b></code>(int b) throws IOException;
<a name="29402"></a> public void <code><b>write</b></code>(byte[] b)
<a name="29403"></a> throws IOException, NullPointerException;
<a name="29404"></a> public void <code><b>write</b></code>(byte[] b, int off, int len)
<a name="29405"></a> throws IOException, NullPointerException,
<a name="29406"></a> IndexOutOfBoundsException;
<a name="29407"></a> public void <code><b>flush</b></code>() throws IOException;
<a name="29408"></a> public void <code><b>close</b></code>() throws IOException;
<a name="29409"></a>}
</pre><a name="29411"></a>
<p><font size=+1><strong>22.15.1 </strong> <code>public abstract void <code><b>write</b></code>(int b) throws IOException</code></font>
<p>
<a name="29412"></a>
The general contract for <code>write</code> is that one byte is written to the output stream. The
byte to be written is the eight low-order bits of the argument <code>b</code>. The 24 high-order
bits of <code>b</code> are ignored.
<p><a name="29413"></a>
If the byte cannot be written for any reason, an <code>IOException</code> is thrown. In particular, an <code>IOException</code> may be thrown if the output stream has been closed <a href="javaio.doc13.html#29445">(§22.15.5)</a>.<p>
<a name="29419"></a>
<p><font size=+1><strong>22.15.2 </strong> <code>public void <code><b>write</b></code>(byte[] b)<br>throws IOException, NullPointerException</code></font>
<p>
<a name="29420"></a>
The general contract for <code>write(b)</code> is that it should have exactly the same effect as
the call <code>write(b,</code> <code>0,</code> <code>b.length)</code> <a href="javaio.doc13.html#29426">(§22.15.3)</a>.
<p><a name="29424"></a>
The <code>write(b)</code> method for class <code>OutputStream</code> in fact makes such a call.<p>
<a name="29426"></a>
<p><font size=+1><strong>22.15.3 </strong> <code>public void <code><b>write</b></code>(byte[] b, int off, int len)<br>throws IOException, NullPointerException,      IndexOutOfBoundsException</code></font>
<p>
<a name="29427"></a>
The general contract for <code>write(b, off, len)</code> is that some of the bytes in the
array <code>b</code> are written to the output stream as if one at a time, in order; element
<code>b[off]</code> is the first byte written and <code>b[off+len-1]</code> is the last byte written by this
operation.
<p><a name="29428"></a>
If <code>b</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="29429"></a>
If <code>off</code> is negative, or <code>len</code> is negative, or <code>off+len</code> is greater than the length of the array <code>b</code>, then an <code>IndexOutOfBoundsException</code> is thrown.<p>
<a name="29430"></a>
If the byte cannot be written for any reason, an <code>IOException</code> is thrown. In particular, an <code>IOException</code> is thrown if the output stream has been closed <a href="javaio.doc13.html#29445">(§22.15.5)</a>.<p>
<a name="29434"></a>
The <code>write(b, off,</code> <code>len)</code> method for class <code>OutputStream</code> simply calls the method <code>write</code> <a href="javaio.doc13.html#29411">(§22.15.1)</a> repeatedly, once for each byte in <code>b</code> to be written.<p>
<a name="29440"></a>
<p><font size=+1><strong>22.15.4 </strong> <code>public void <code><b>flush</b></code>() throws IOException</code></font>
<p>
<a name="29441"></a>
The general contract of <code>flush</code> is that calling it is an indication that, if any bytes
previously written have been buffered by the implementation of the output stream,
such bytes should immediately be written to their intended destination.
<p><a name="29442"></a>
The <code>flush</code> method for class <code>OutputStream</code> does nothing and simply returns.<p>
<a name="29445"></a>
<p><font size=+1><strong>22.15.5 </strong> <code>public void <code><b>close</b></code>() throws IOException</code></font>
<p>
<a name="29446"></a>
The general contract of <code>close</code> is that it closes the output stream. A closed stream
cannot perform output operations and cannot be reopened.
<p><a name="29447"></a>
The <code>close</code> method for class <code>OutputStream</code> does nothing and simply returns.<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javaio.doc12.html">Prev</a> | <a href="javaio.doc14.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright © 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:doug.kramer@sun.com">doug.kramer@sun.com</a>
</font>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -