📄 javaio.doc19.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.doc18.html">Prev</a> | <a href="javaio.doc20.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
<a name="9231"></a>
<center><h1>22.21 The Class <code>java.io.DataOutputStream</code></h1></center>
<a name="33862"></a>
A data output stream provides facilities for converting data of diverse types into
character sequence of specific formats that are then sent to some output stream.
<p><pre><a name="9232"></a>public class <code><b>DataOutputStream</b></code> extends FilterOutputStream
<a name="23983"></a> implements DataOutput {
<a name="9233"></a> protected int <code><b>written</b></code>;
<a name="9234"></a> public <code><b>DataOutputStream</b></code>(OutputStream out);
<a name="9235"></a> public void <code><b>write</b></code>(int b) throws IOException;
<a name="9236"></a> public void <code><b>write</b></code>(byte[] b, int off, int len)
<a name="32467"></a> throws IOException, NullPointerException,
<a name="32468"></a> IndexOutOfBoundsException;
<a name="9237"></a> public void <code><b>flush</b></code>() throws IOException;
<a name="9238"></a> public final void <code><b>writeBoolean</b></code>(boolean v) throws IOException;
<a name="9239"></a> public final void <code><b>writeByte</b></code>(int v) throws IOException;
<a name="9240"></a> public final void <code><b>writeShort</b></code>(int v) throws IOException;
<a name="9241"></a> public final void <code><b>writeChar</b></code>(int v) throws IOException;
<a name="9242"></a> public final void <code><b>writeInt</b></code>(int v) throws IOException;
<a name="9243"></a> public final void <code><b>writeLong</b></code>(long v) throws IOException;
<a name="9244"></a> public final void <code><b>writeFloat</b></code>(float v) throws IOException;
<a name="9245"></a> public final void <code><b>writeDouble</b></code>(double v) throws IOException;
<a name="9246"></a> public final void <code><b>writeBytes</b></code>(String s)
<a name="32475"></a> throws IOException, NullPointerException;
<a name="9247"></a> public final void <code><b>writeChars</b></code>(String s)
<a name="32476"></a> throws IOException, NullPointerException;
<a name="9248"></a> public final void <code><b>writeUTF</b></code>(String str)
<a name="32477"></a> throws IOException, NullPointerException;
<a name="9249"></a> public final int <code><b>size</b></code>();
<a name="9250"></a>}
</pre><a name="9251"></a>
<p><font size=+1><strong>22.21.1 </strong> <code>protected int <code><b>written</b></code>;</code></font>
<p>
<a name="23975"></a>
This field contains the number of bytes written to the stream so far.
<p><a name="9252"></a>
<p><font size=+1><strong>22.21.2 </strong> <code>public <code><b>DataOutputStream</b></code>(OutputStream out)</code></font>
<p>
<a name="23951"></a>
This constructor initializes a newly created <code>DataOutputStream</code> by saving its
argument, the output stream <code>out</code>, for later use. The counter <code>written</code> is set to zero.
<p><a name="9253"></a>
<p><font size=+1><strong>22.21.3 </strong> <code>public void <code><b>write</b></code>(int b) throws IOException</code></font>
<p>
<a name="27480"></a>
The byte for this operation (the low eight bits of the argument <code>b</code>) is written to the
contained output stream. If no exception is thrown, the counter <code>written</code> is incremented
by <code>1</code>.
<p><a name="27492"></a>
Implements the <code>write</code> method of <code>OutputStream</code> <a href="javaio.doc13.html#29411">(§22.15.1)</a>.<p>
<a name="27481"></a>
<p><font size=+1><strong>22.21.4 </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="27494"></a>
Bytes for this operation are written to the contained output stream. If no exception
is thrown, the counter <code>written</code> is incremented by <code>len</code>.
<p><a name="27499"></a>
Overrides the <code>write</code> method of <code>OutputStream</code> <a href="javaio.doc13.html#29426">(§22.15.3)</a>.<p>
<a name="27451"></a>
<p><font size=+1><strong>22.21.5 </strong> <code>public void <code><b>flush</b></code>() throws IOException</code></font>
<p>
<a name="27455"></a>
The contained output stream is flushed.
<p><a name="27503"></a>
Overrides the <code>flush</code> method of <code>OutputStream</code> <a href="javaio.doc13.html#29440">(§22.15.4)</a>.<p>
<a name="27456"></a>
<p><font size=+1><strong>22.21.6 </strong> <code>public final void <code><b>writeBoolean</b></code>(boolean v)<br>throws IOException</code></font>
<p>
<a name="23962"></a>
See the general contract of the <code>writeBoolean</code> method of <code>DataOutput</code> <a href="javaio.doc.html#28974">(§22.2.4)</a>.
<p><a name="23963"></a>
The byte for this operation is written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by <code>1</code>.<p>
<a name="9257"></a>
<p><font size=+1><strong>22.21.7 </strong> <code>public final void <code><b>writeByte</b></code>(int v) throws IOException</code></font>
<p>
<a name="23988"></a>
See the general contract of the <code>writeByte</code> method of <code>DataOutput</code> <a href="javaio.doc.html#28981">(§22.2.5)</a>.
<p><a name="23989"></a>
The byte for this operation is written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by <code>1</code>.<p>
<a name="9258"></a>
<p><font size=+1><strong>22.21.8 </strong> <code>public final void <code><b>writeShort</b></code>(int v) throws IOException</code></font>
<p>
<a name="23996"></a>
See the general contract of the <code>writeShort</code> method of <code>DataOutput</code> <a href="javaio.doc.html#28988">(§22.2.6)</a>.
<p><a name="23997"></a>
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by <code>2</code>.<p>
<a name="9259"></a>
<p><font size=+1><strong>22.21.9 </strong> <code>public final void <code><b>writeChar</b></code>(int v) throws IOException</code></font>
<p>
<a name="24004"></a>
See the general contract of the <code>writeChar</code> method of <code>DataOutput</code> <a href="javaio.doc.html#28997">(§22.2.7)</a>.
<p><a name="24094"></a>
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by <code>2</code>.<p>
<a name="9260"></a>
<p><font size=+1><strong>22.21.10 </strong> <code>public final void <code><b>writeInt</b></code>(int v) throws IOException</code></font>
<p>
<a name="24012"></a>
See the general contract of the <code>writeInt</code> method of <code>DataOutput</code> <a href="javaio.doc16.html#29567">(§22.2.8)</a>.
<p><a name="24098"></a>
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by <code>4</code>.<p>
<a name="9261"></a>
<p><font size=+1><strong>22.21.11 </strong> <code>public final void <code><b>writeLong</b></code>(long v) throws IOException</code></font>
<p>
<a name="24020"></a>
See the general contract of the <code>writeLong</code> method of <code>DataOutput</code> <a href="javaio.doc.html#29017">(§22.2.9)</a>.
<p><a name="24102"></a>
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by <code>8</code>.<p>
<a name="9262"></a>
<p><font size=+1><strong>22.21.12 </strong> <code>public final void <code><b>writeFloat</b></code>(float v) throws IOException</code></font>
<p>
<a name="24028"></a>
See the general contract of the <code>writeFloat</code> method of <code>DataOutput</code> <a href="javaio.doc.html#29032">(§22.2.10)</a>.
<p><a name="24106"></a>
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by <code>4</code>.<p>
<a name="9263"></a>
<p><font size=+1><strong>22.21.13 </strong> <code>public final void <code><b>writeDouble</b></code>(double v) throws IOException</code></font>
<p>
<a name="24036"></a>
See the general contract of the <code>writeDouble</code> method of <code>DataOutput</code> <a href="javaio.doc.html#29045">(§22.2.11)</a>.
<p><a name="24110"></a>
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by <code>8</code>.<p>
<a name="9264"></a>
<p><font size=+1><strong>22.21.14 </strong> <code>public final void <code><b>writeBytes</b></code>(String s)<br>throws IOException, NullPointerException,      IndexOutOfBoundsException</code></font>
<p>
<a name="24044"></a>
See the general contract of the <code>writeBytes</code> method of <code>DataOutput</code> <a href="javaio.doc.html#29058">(§22.2.12)</a>.
<p><a name="24114"></a>
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by the length of <code>s</code>.<p>
<a name="9265"></a>
<p><font size=+1><strong>22.21.15 </strong> <code>public final void <code><b>writeChars</b></code>(String s)<br>throws IOException, NullPointerException,      IndexOutOfBoundsException</code></font>
<p>
<a name="24052"></a>
See the general contract of the <code>writeChars</code> method of <code>DataOutput</code> <a href="javaio.doc.html#29066">(§22.2.13)</a>.
<p><a name="32487"></a>
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by twice the length of <code>s</code>.<p>
<a name="32488"></a>
<p><font size=+1><strong>22.21.16 </strong> <code>public final void <code><b>writeUTF</b></code>(String str)<br>throws IOException, NullPointerException,      IndexOutOfBoundsException</code></font>
<p>
<a name="32492"></a>
See the general contract of the <code>writeUTF</code> method of <code>DataOutput</code> <a href="javaio.doc.html#29074">(§22.2.14)</a>.
<p><a name="24122"></a>
Bytes for this operation are written to the contained output stream. If no exception is thrown, the counter <code>written</code> is incremented by the total number of bytes written to the output stream. This will be at least two plus the length of <code>s</code>, and at most two plus thrice the length of <code>s</code>.<p>
<a name="9267"></a>
<p><font size=+1><strong>22.21.17 </strong> <code>public final int <code><b>size</b></code>()</code></font>
<p>
<a name="23976"></a>
The <code>size</code> method returns the current value of the counter <code>written</code>, the number of
bytes written to the stream so far.
<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javaio.doc18.html">Prev</a> | <a href="javaio.doc20.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 + -