Chararraywriter Class Example

Source: Internet
Author: User

/*

Chararraywriter implements the output stream with arrays as the target. Chararraywriter has two constructor functions: chararraywriter () chararraywriter (INT numchars) in the first form. A buffer of the default length is created. Second, the buffer length is specified by numchars. The buffer is stored in the Buf member of chararraywriter. The buffer size can automatically increase as needed. The number of characters maintained by the buffer is included in the count member of chararraywriter. Both Buf and count are protected domains.

*/

// Demonstrate chararraywriter.
Import java. Io .*;
Class chararraywriterdemo {
Public static void main (string [] ARGs) throws ioexception {
Chararraywriter F = new chararraywriter ();
String S = "This shocould end up in the array ";
Char Buf [] = new char [S. Length ()];
S. getchars (0, S. Length (), Buf, 0 );
F. Write (BUF );
System. Out. println ("buffer as a string ");
System. Out. println (F. tostring ());
System. Out. println ("into array ");
Char C [] = f. tochararray ();
For (INT I = 0; I <C. length; I ++ ){
System. Out. Print (char) C [I]);
}
System. Out. println ("/nto a filewriter ()");

Filewriter F2 = new filewriter ("test.txt ");
F. writeto (F2 );
F2.close ();

System. Out. println ("doing a reset ");
F. Reset ();
For (INT I = 0; I <3; I ++)
F. Write ('x ');
System. Out. println (F. tostring ());
}
}

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.