Bytearrayinputstream and Bytearrayoutputstream,printstream

Source: Internet
Author: User

What is the use of Bytearrayinputstream and Bytearrayoutputstream this two. Bytearrayinputstream can be called packing flow, Bytearrayoutputstream can be called intercept flow.


When a inputstream parameter is needed, proceed is byte[] what to do? How to pass the past satisfies the parameter. Do you want to write the array to a file and then get the path to InputStream. There is an easy way to wrap it in Bytearraystream.


Give the array as a parameter to the Bytearraystream constructor, and then let us wrap our array into a subclass of the inputstream below Bytearraystream, Then you can put the packaged bytearraystream to InputStream.


What does the Bytearrayoutputstream intercept stream mean. When the method parameter needs a outputstream, then takes the OutputStream output, what method can let him not output, the object wants the output content interception. Bytearraystream can do it.


When you new good bytearraystream, and then take this as a parameter passed in, call the Tobytearray method, get a byte[], converted to string for display, maybe he wrote Ah not according to the usual time of the incoming path, according to the path output, But read it on the Bytearraystream.


Api:

System: In the facilities provided by the system class, there are standard inputs, standard outputs, and error output streams;

Out: "standard" output stream. This stream is open and ready to accept output data.

PrintStream: Adds functionality to other output streams so that they can easily print various data-value representations.


PrintStream is also an output stream that can specify the output of the file, and the default systen.out output in the console. PrintStream can be inherited and manipulated before the println output under PrintStream is invoked.


Specify the output of the file, need System.setout (); API: Reassign the standard output stream.


1:system.out to the standard output stream, guess: output to the control Eclipse System console or CMD in this Visual window program, 2:new printstream ("D:/a.txt") by the specified path, output content

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.