Java Io learning notes (5): Memory Operation Flow

Source: Internet
Author: User
ArticleDirectory
    • Bytearrayinputstream and bytearrayoutputstream
Bytearrayinputstream and bytearrayoutputstream

TheProgramThe output and input are both from the file. Of course, you can also set the output position on the memory. In this case, you must use bytearrayinputstream and bytearrayoutputstream to complete the input and output functions.

The main function of bytearrayinputstream is to input content into the memory.

The main function of bytearrayoutputstream is to output data in the memory.

In this case, the memory should be used as the Operation Point.


Bytearrayinputstream class definition:

Public class bytearrayinputstream extends inputstream

Constructor:

Public bytearrayinputstream (byte [] BUF)

Accept a byte array. In fact, the input to the memory is to pass data into the memory in the constructor.

Bytearrayoutputstream: the output is to write data from the memory.

Public void write (int B)

 

The following is a case-insensitive Conversion Program completed by the memory operation stream:

 1   Import Java. Io. bytearrayinputstream;
2 Import Java. Io. bytearrayoutputstream;
3 Import Java. Io. ioexception;
4 Import Java. Io. inputstream;
5 Import Java. Io. outputstream;
6
7 Public Class Test22 {
8 Public Static Void Main (string [] ARGs) Throws Ioexception {
9 String STR = "Hello world !!! ";
10 Inputstream input = New Bytearrayinputstream (Str. getbytes ());
11 Outputstream output = New Bytearrayoutputstream ();
12 Int Temp = 0;
13 While (Temp = input. Read ())! =-1 ){
14 Output. Write (character. tolowercase (temp ));
15 }
16 Input. Close ();
17 Output. Close ();
18 System. Out. println (output. tostring ());
19 }
20 }

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.