Java Basics Review Javaio class--memory operation Flow Bytearrayinputstream and Bytearrayoutputsteam (Operation byte array)

Source: Internet
Author: User

Look directly at the code:

 PackageCn.itcast.io.p6.bytestream;ImportJava.io.ByteArrayInputStream;ImportJava.io.ByteArrayOutputStream;Importjava.io.IOException; Public classBytearraystreamdemo {/**     * @paramargs *@throwsIOException * Features * 1. Memory operation Flow * 2. Do not operate the underlying resource, do not invoke the underlying resource of the operating system, manipulate the data in memory, the memory stream does not need to close * 3. After you close the stream you can also use the * This example: memory operation Flow Complete A program that converts a case to a lowercase letter:*/     Public Static voidMain (string[] args) {String str= "HELLO world!"; Bytearrayinputstream bis=NewBytearrayinputstream (Str.getbytes ());//entering content into memoryBytearrayoutputstream BOS =NewBytearrayoutputstream ();//to output the in-memory data        intCH = 0; Bis.skip (2);//Skip Two bytesSystem.out.println (Bis.available ());//returns the number of bytes remaining in this input stream read (or skipped)         while((Ch=bis.read ())!=-1) {bos.write (character.tolowercase (CH));//Convert size characters to lowercase} System.out.println (Bos.tostring ()); }}

Output: Since two bytes are skipped, HELLO world! has a total of 12 bytes, then the remaining 10 bytes.

10
Llo world!

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.