Java IO streaming data streams datainputstream, DataOutputStream, Bytearrayinputstream, Bytearrayoutputstream

Source: Internet
Author: User

Example program:

 Packageio;ImportJava.io.ByteArrayInputStream;ImportJava.io.ByteArrayOutputStream;ImportJava.io.DataInputStream;ImportJava.io.DataOutputStream;Importjava.io.IOException; Public classTestdatastream { Public Static voidMain (string[] args) {/*** Create a byte array in memory, Bytearrayoutputstream this pipe is godless to the memory*/Bytearrayoutputstream BAOs=NewBytearrayoutputstream (); //writes the basic Java data type to the output streamDataOutputStream dos =NewDataOutputStream (BAOs); Try {            //writes a double type, 8 bytesdos.writedouble (Math.random ()); Dos.writeboolean (true);//Boolean type 1 bytes                        /*** Equivalent to this pipe godless to the top of Bytearrayoutputstream.             Got a reference to the byte array in memory. */Bytearrayinputstream Bais=NewBytearrayinputstream (Baos.tobytearray ()); //The number of readable bytes remaining in the input streamSystem.out.println (Bais.available ());//altogether 9 bytesdatainputstream Dis=NewDataInputStream (Bais);            System.out.println (Dis.readdouble ());            System.out.println (Dis.readboolean ()); /*** After Colse, the memory byte array is gone. */Dos.close ();        Dis.close (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }    }}

Java IO stream data flow datainputstream, DataOutputStream, Bytearrayinputstream, Bytearrayoutputstream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.