CharaRrayWriter class example

xiaoxiao2021-04-07  337

/ *

CharaRrayWriter implements an output stream as an array as a target. CharaRrayWriter has two constructor:

Chararraywriter ()

Chararraywriter (int Numchars)

In the first form, a buffer for a default length is created. In the second form, the buffer length is specified by NumChars. The buffer is saved in the BUF member of CharaRrayWriter. The buffer size can be automatically increased in the case of need. The number of characters held by the buffer is included in the count member of CharaRrayWriter. 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 should 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

FileWriter F2 = New FileWriter ("Test.txt"); F.Writto (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.toToString ());}}

转载请注明原文地址:https://www.9cbs.com/read-132553.html

New Post(0)