﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-rainmanyang-文章分类-java i/o</title><link>http://www.blogjava.net/rainmanyang/category/34935.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 01 Oct 2008 18:08:32 GMT</lastBuildDate><pubDate>Wed, 01 Oct 2008 18:08:32 GMT</pubDate><ttl>60</ttl><item><title>ByteArrayOutputStream和ByteArrayInputStream详解</title><link>http://www.blogjava.net/rainmanyang/articles/232045.html</link><dc:creator>rainman</dc:creator><author>rainman</author><pubDate>Wed, 01 Oct 2008 15:39:00 GMT</pubDate><guid>http://www.blogjava.net/rainmanyang/articles/232045.html</guid><wfw:comment>http://www.blogjava.net/rainmanyang/comments/232045.html</wfw:comment><comments>http://www.blogjava.net/rainmanyang/articles/232045.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rainmanyang/comments/commentRss/232045.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rainmanyang/services/trackbacks/232045.html</trackback:ping><description><![CDATA[ByteArrayOutputStream类是在创建它的实例时，程序内部创建一个byte型别数组的缓冲区，然后利用ByteArrayOutputStream和ByteArrayInputStream的实例向数组中写入或读出byte型数据。在网络传输中我们往往要传输很多变量，我们可以利用ByteArrayOutputStream把所有的变量收集到一起，然后一次性把数据发送出去。具体用法如下:
<p><span lang="EN-US" style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" xml:lang="EN-US">ByteArrayOutputStream:&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr></span> <span style="font-size: 10.5pt; font-family: 宋体; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'">可以捕获内存缓冲区的数据，转换成字节数组。</span></p>
<p><span style="font-size: 10.5pt; font-family: 宋体; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'"><span style="font-size: 10.5pt; font-family: 宋体; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'"><span lang="EN-US" style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" xml:lang="EN-US"><span lang="EN-US" style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" xml:lang="EN-US">ByteArrayInputStream:</span> <span style="font-size: 10.5pt; font-family: 宋体; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'">可以将字节数组转化为输入流<br />
</span></span></span></span></p>
<p><span style="font-size: 10.5pt; font-family: 宋体; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'"><span lang="EN-US" style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" xml:lang="EN-US"><span style="font-size: 10.5pt; font-family: 宋体; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'"></p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">&nbsp;1</span><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.io.</span><span style="color: #000000">*</span><span style="color: #000000">;<br />
</span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img id="Codehighlighter1_37_501_Open_Image" onclick="this.style.display='none'; Codehighlighter1_37_501_Open_Text.style.display='none'; Codehighlighter1_37_501_Closed_Image.style.display='inline'; Codehighlighter1_37_501_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_37_501_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_37_501_Closed_Text.style.display='none'; Codehighlighter1_37_501_Open_Image.style.display='inline'; Codehighlighter1_37_501_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;test&nbsp;</span><span id="Codehighlighter1_37_501_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_37_501_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img id="Codehighlighter1_79_499_Open_Image" onclick="this.style.display='none'; Codehighlighter1_79_499_Open_Text.style.display='none'; Codehighlighter1_79_499_Closed_Image.style.display='inline'; Codehighlighter1_79_499_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_79_499_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_79_499_Closed_Text.style.display='none'; Codehighlighter1_79_499_Open_Image.style.display='inline'; Codehighlighter1_79_499_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;</span><span id="Codehighlighter1_79_499_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_79_499_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br />
</span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br />
</span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">2</span><span style="color: #000000">;<br />
</span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;ByteArrayOutputStream&nbsp;bout&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ByteArrayOutputStream();<br />
</span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;bout.write(a);<br />
</span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;bout.write(b);<br />
</span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;bout.write(c);<br />
</span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;buff&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;bout.toByteArray();<br />
</span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">buff.length;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />
</span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;System.out.println(buff[i]);<br />
</span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">***********************</span><span style="color: #000000">"</span><span style="color: #000000">);<br />
</span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;ByteArrayInputStream&nbsp;bin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ByteArrayInputStream(buff);<br />
</span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_466_496_Open_Image" onclick="this.style.display='none'; Codehighlighter1_466_496_Open_Text.style.display='none'; Codehighlighter1_466_496_Closed_Image.style.display='inline'; Codehighlighter1_466_496_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_466_496_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_466_496_Closed_Text.style.display='none'; Codehighlighter1_466_496_Open_Image.style.display='inline'; Codehighlighter1_466_496_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">((b</span><span style="color: #000000">=</span><span style="color: #000000">bin.read())</span><span style="color: #000000">!=-</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;</span><span id="Codehighlighter1_466_496_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_466_496_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;System.out.println(b);<br />
</span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><br />
</span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span></div>
<p>如上所示,ByteArrayOutputStream把内存中的数据读到字节数组中,而ByteArrayInputStream又把字节数组中的字节以流的形式读出,实现了对同一个字节数组的操作.</span></span></span></p>
<p><span style="font-size: 10.5pt; font-family: 宋体; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'"><span lang="EN-US" style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" xml:lang="EN-US"><span style="font-size: 10.5pt; font-family: 宋体; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'">综合<span lang="EN-US" style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" xml:lang="EN-US">DataOutputStream&amp;DataInputStream的作用和功能,与<font face="宋体">ByteArrayOutputStream和ByteArrayInputSream使用将更方便.此时<span lang="EN-US" style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" xml:lang="EN-US">DataOutputStream&amp;DataInputStream封闭了字节流,以适当的形式读出了字节数组中的数据.如下所示:</span></font></span></span></span></span></p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">&nbsp;1</span><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.io.</span><span style="color: #000000">*</span><span style="color: #000000">;<br />
</span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br />
</span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img id="Codehighlighter1_37_553_Open_Image" onclick="this.style.display='none'; Codehighlighter1_37_553_Open_Text.style.display='none'; Codehighlighter1_37_553_Closed_Image.style.display='inline'; Codehighlighter1_37_553_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_37_553_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_37_553_Closed_Text.style.display='none'; Codehighlighter1_37_553_Open_Image.style.display='inline'; Codehighlighter1_37_553_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;test&nbsp;</span><span id="Codehighlighter1_37_553_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span><span id="Codehighlighter1_37_553_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img id="Codehighlighter1_97_551_Open_Image" onclick="this.style.display='none'; Codehighlighter1_97_551_Open_Text.style.display='none'; Codehighlighter1_97_551_Closed_Image.style.display='inline'; Codehighlighter1_97_551_Closed_Text.style.display='inline';" alt="" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_97_551_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_97_551_Closed_Text.style.display='none'; Codehighlighter1_97_551_Open_Image.style.display='inline'; Codehighlighter1_97_551_Open_Text.style.display='inline';" alt="" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;main(String[]&nbsp;args)</span><span style="color: #0000ff">throws</span><span style="color: #000000">&nbsp;IOException&nbsp;</span><span id="Codehighlighter1_97_551_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.blogjava.net/Images/dot.gif" /></span><span id="Codehighlighter1_97_551_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;ByteArrayOutputStream&nbsp;bout&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ByteArrayOutputStream();<br />
</span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;DataOutputStream&nbsp;dout&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;DataOutputStream(bout);<br />
</span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;String&nbsp;name&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">xxy</span><span style="color: #000000">"</span><span style="color: #000000">;<br />
</span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;age&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">84</span><span style="color: #000000">;<br />
</span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;dout.writeUTF(name);<br />
</span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;dout.writeInt(age);<br />
</span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;buff&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;bout.toByteArray();<br />
</span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;ByteArrayInputStream&nbsp;bin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ByteArrayInputStream(buff);<br />
</span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;DataInputStream&nbsp;dis&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;DataInputStream(bin);<br />
</span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;String&nbsp;newName&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;dis.readUTF();<br />
</span><span style="color: #008080">15</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;newAge&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;dis.readInt();<br />
</span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;System.out.println(newName</span><span style="color: #000000">+</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">newAge);<br />
</span><span style="color: #008080">17</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">18</span><span style="color: #000000"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br />
</span></div>
<img src ="http://www.blogjava.net/rainmanyang/aggbug/232045.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rainmanyang/" target="_blank">rainman</a> 2008-10-01 23:39 <a href="http://www.blogjava.net/rainmanyang/articles/232045.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>