📄 javaio.doc.html
字号:
<a name="28967"></a>
If <code>b.length</code> is zero, then no bytes are written. Otherwise, the byte <code>b[0]</code> is written first, then <code>b[1]</code>, and so on; the last byte written is <code>b[b.length-1]</code>.<p>
<a name="28968"></a>
<p><font size=+1><strong>22.2.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="28969"></a>
The general contract for <code>write</code> is that <code>len</code> bytes from array <code>b</code> are written, in order,
to the output stream.
<p><a name="28970"></a>
If <code>b</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="28971"></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="28972"></a>
If <code>len</code> is zero, then no bytes are written. Otherwise, the byte <code>b[off]</code> is written first, then <code>b[off+1]</code>, and so on; the last byte written is <code>b[off+len-1]</code>.<p>
<a name="28974"></a>
<p><font size=+1><strong>22.2.4 </strong> <code>public void <code><b>writeBoolean</b></code>(boolean v) throws IOException</code></font>
<p>
<a name="28975"></a>
The general contract for <code>writeBoolean</code> is that one byte is written to the output
stream. If the argument <code>v</code> is <code>true</code>, the value <code>(byte)1</code> is written; if <code>v</code> is <code>false</code>, the
value <code>(byte)0</code> is written.
<p><a name="28976"></a>
The byte written by this method may be read by the <code>readBoolean</code> method of interface <code>DataInput</code> <a href="javaio.doc.html#28817">(§22.1.4)</a>, which will then return a <code>boolean</code> equal to <code>v</code>.<p>
<a name="28981"></a>
<p><font size=+1><strong>22.2.5 </strong> <code>public void <code><b>writeByte</b></code>(int v) throws IOException</code></font>
<p>
<a name="28982"></a>
The general contract for <code>writeByte</code> is that one byte is written to the output stream
to represent the value of the argument. 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. (This means
that <code>writeByte</code> does exactly the same thing as <code>write</code> for an integer argument.)
<p><a name="28983"></a>
The byte written by this method may be read by the <code>readByte</code> method of interface <code>DataInput</code> <a href="javaio.doc.html#28824">(§22.1.5)</a>, which will then return a <code>byte</code> equal to <code>(byte)v</code>.<p>
<a name="28988"></a>
<p><font size=+1><strong>22.2.6 </strong> <code>public void <code><b>writeShort</b></code>(int v) throws IOException</code></font>
<p>
<a name="28989"></a>
The general contract for <code>writeShort</code> is that two bytes are written to the output
stream to represent the value of the argument. The byte values to be written, in the
order shown, are:
<p><pre><a name="28990"></a>
(byte)(0xff & (v >> 8))
<a name="28991"></a>(byte)(0xff & v)
</pre><a name="28992"></a>
The bytes written by this method may be read by the <code>readShort</code> method of interface <code>DataInput</code> <a href="javaio.doc.html#28838">(§22.1.7)</a>, which will then return a <code>short</code> equal to <code>(short)v</code>.<p>
<a name="28997"></a>
<p><font size=+1><strong>22.2.7 </strong> <code>public void <code><b>writeChar</b></code>(int v) throws IOException</code></font>
<p>
<a name="28998"></a>
The general contract for <code>writeChar</code> is that two bytes are written to the output
stream to represent the value of the argument. The byte values to be written, in the
order shown, are:
<p><pre><a name="28999"></a>
(byte)(0xff & (v >> 8))
<a name="29000"></a>(byte)(0xff & v)
</pre><a name="29001"></a>
The bytes written by this method may be read by the <code>readChar</code> method of interface <code>DataInput</code> <a href="javaio.doc.html#28853">(§22.1.9)</a>, which will then return a <code>char</code> equal to <code>(char)v</code>.<p>
<a name="29006"></a>
<p><font size=+1><strong>22.2.8 </strong> <code>public void <code><b>writeInt</b></code>(int v) throws IOException</code></font>
<p>
<a name="29007"></a>
The general contract for <code>writeInt</code> is that four bytes are written to the output
stream to represent the value of the argument. The byte values to be written, in the
order shown, are:
<p><pre><a name="29008"></a>
(byte)(0xff & (v >> 24))
<a name="29009"></a>(byte)(0xff & (v >> 16))
<a name="29010"></a>(byte)(0xff & (v >>    8))
<a name="29011"></a>(byte)(0xff & v)
</pre><a name="29012"></a>
The bytes written by this method may be read by the <code>readInt</code> method of interface <code>DataInput</code> <a href="javaio.doc.html#28860">(§22.1.10)</a>, which will then return an <code>int</code> equal to <code>v</code>.<p>
<a name="29017"></a>
<p><font size=+1><strong>22.2.9 </strong> <code>public void <code><b>writeLong</b></code>(long v) throws IOException</code></font>
<p>
<a name="29018"></a>
The general contract for <code>writeLong</code> is that four bytes are written to the output
stream to represent the value of the argument. The byte values to be written, in the
order shown, are:
<p><pre><a name="29019"></a>
(byte)(0xff & (v >> 56))
<a name="29020"></a>(byte)(0xff & (v >> 48))
<a name="29021"></a>(byte)(0xff & (v >> 40))
<a name="29022"></a>(byte)(0xff & (v >> 32))
<a name="29023"></a>(byte)(0xff & (v >> 24))
<a name="29024"></a>(byte)(0xff & (v >> 16))
<a name="29025"></a>(byte)(0xff & (v >>    8))
<a name="29026"></a>(byte)(0xff & v)
</pre><a name="29027"></a>
The bytes written by this method may be read by the <code>readLong</code> method of interface <code>DataInput</code> <a href="javaio.doc.html#28871">(§22.1.11)</a>, which will then return a <code>long</code> equal to <code>v</code>.<p>
<a name="29032"></a>
<p><font size=+1><strong>22.2.10 </strong> <code>public void <code><b>writeFloat</b></code>(float v) throws IOException</code></font>
<p>
<a name="29033"></a>
The general contract for <code>writeFloat</code> is that four bytes are written to the output
stream to represent the value of the argument. It does this as if it first converts this
<code>float</code> value to an <code>int</code> in exactly the manner of the <code>Float.floatToIntBits</code>
method <a href="javalang.doc8.html#14423">(§20.9.22)</a> and then writes the <code>int</code> value in exactly the manner of the
<code>writeInt</code> method <a href="javaio.doc16.html#29567">(§22.2.8)</a>.
<p><a name="29040"></a>
The bytes written by this method may be read by the <code>readFloat</code> method of interface <code>DataInput</code> <a href="javaio.doc.html#28886">(§22.1.12)</a>, which will then return a <code>float</code> equal to <code>v</code>.<p>
<a name="29045"></a>
<p><font size=+1><strong>22.2.11 </strong> <code>public void <code><b>writeDouble</b></code>(double v) throws IOException</code></font>
<p>
<a name="29046"></a>
The general contract for <code>writeDouble</code> is that eight bytes are written to the output
stream to represent the value of the argument. It does this as if it first converts this
<code>double</code> value to a <code>long</code> in exactly the manner of the <code>Double.doubleToLongBits</code>
method <a href="javalang.doc9.html#13863">(§20.10.21)</a> and then writes the <code>long</code> value in exactly the manner of the
<code>writeLong</code> method <a href="javaio.doc.html#29017">(§22.2.9)</a>.
<p><a name="29053"></a>
The bytes written by this method may be read by the <code>readDouble</code> method of interface <code>DataInput</code> <a href="javaio.doc.html#28899">(§22.1.13)</a>, which will then return a <code>double</code> equal to <code>v</code>.<p>
<a name="29058"></a>
<p><font size=+1><strong>22.2.12 </strong> <code>public void <code><b>writeBytes</b></code>(String s)<br>throws IOException, NullPointerException</code></font>
<p>
<a name="29059"></a>
The general contract for <code>writeBytes</code> is that for every character in the string <code>s</code>,
taken in order, one byte is written to the output stream.
<p><a name="29060"></a>
If <code>s</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="29061"></a>
If <code>s.length</code> is zero, then no bytes are written. Otherwise, the character <code>s[0]</code> is written first, then <code>s[1]</code>, and so on; the last character written is <code>s[s.length-1]</code>. For each character, one byte is written, the low-order byte, in exactly the manner of the <code>writeByte</code> method <a href="javaio.doc.html#28981">(§22.2.5)</a>. The high-order eight bits of each character in the string are ignored.<p>
<a name="29066"></a>
<p><font size=+1><strong>22.2.13 </strong> <code>public void <code><b>writeChars</b></code>(String s)<br>throws IOException, NullPointerException</code></font>
<p>
<a name="29067"></a>
The general contract for <code>writeChars</code> is that every character in the string <code>s</code> is written,
in order, to the output stream, two bytes per character.
<p><a name="29068"></a>
If <code>s</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="29069"></a>
If <code>s.length</code> is zero, then no characters are written. Otherwise, the character <code>s[0]</code> is written first, then <code>s[1]</code>, and so on; the last character written is <code>s[s.length-1]</code>. For each character, two bytes are actually written, high-order byte first, in exactly the manner of the <code>writeChar</code> method <a href="javaio.doc.html#28997">(§22.2.7)</a>.<p>
<a name="29074"></a>
<p><font size=+1><strong>22.2.14 </strong> <code>public void <code><b>writeUTF</b></code>(String s)<br>throws IOException, NullPointerException</code></font>
<p>
<a name="29075"></a>
The general contract for <code>writeUTF</code> is that two bytes of length information are
written to the output stream, followed by the Java modified UTF representation of
every character in the string <code>s</code>.
<p><a name="29076"></a>
If <code>s</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="29077"></a>
Each character in the string <code>s</code> is converted to a group of one, two, or three bytes, depending on the value of the character.<p>
<a name="29078"></a>
If a character <code>c</code> is in the range <code>'\u0001'</code> through <code>'\u007f'</code>, it is represented by one byte:<p>
<pre><a name="29079"></a>(byte)c
</pre><a name="29080"></a>
If a character <code>c</code> is <code>'\u0000'</code> or is in the range <code>'\u0080'</code> through <code>'\u07ff'</code>, then it is represented by two bytes, to be written in the order shown:<p>
<pre><a name="29081"></a>
(byte)(0xc0 | (0x1f & (c >> 6)))
<a name="29082"></a>(byte)(0x80 | (0x3f & c))
</pre><a name="29083"></a>
If a character <code>c</code> is in the range <code>'\u0800'</code> through <code>'\uffff'</code>, then it is represented by three bytes, to be written in the order shown:<p>
<pre><a name="29084"></a>
(byte)(0xc0 | (0x0f & (c >> 12)))
<a name="29085"></a>(byte)(0x80 | (0x3f & (c >>    6)))
<a name="29086"></a>(byte)(0x80 | (0x3f & c))
</pre><a name="29087"></a>
First, the total number of bytes needed to represent all the characters of <code>s</code> is calculated. If this number is larger than <code>65535</code>, then a <code>UTFDataFormatError</code> is thrown. Otherwise, this length is written to the output stream in exactly the manner  of the <code>writeShort</code> method <a href="javaio.doc.html#28988">(§22.2.6)</a>; after this, the one-, two-, or three-byte representation of each character in the string <code>s</code> is written.<p>
<a name="29091"></a>
The bytes written by this method may be read by the <code>readUTF</code> method of interface <code>DataInput</code> <a href="javaio.doc.html#28916">(§22.1.15)</a>, which will then return a <code>String</code> equal to <code>s</code>.<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javautil.doc12.html">Prev</a> | <a href="javaio.doc1.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 + -