/* Filewriter creates a writer class that can write files. The most common constructor is filewriter (string filepath) filewriter (string filepath, Boolean append) filewriter (File fileobj). They can cause ioexception or securityexception exceptions. Here, filepath is the full path of the file, and fileobj is the file object that describes the file. If append is true, the output is appended to the end of the file. The creation of the filewriter class does not depend on whether the file exists or not. Before creating a file, filewriter opens the file as an output when creating the object. If you try to open a read-only file, an ioexception is thrown. */
// Demonstrate filewriter.
Import java. Io .*;
Class filewriterdemo {
Public static void main (string [] ARGs) throws exception {
String source = "Now is the time for all good men/N"
+ "To come to the aid of their country/N"
+ "And pay their due taxes .";
Char buffer [] = new char [source. Length ()];
Source. getchars (0, source. Length (), buffer, 0 );
Filewriter f0 = new filewriter ("file1.txt ");
For (INT I = 0; I <buffer. length; I + = 2 ){
F0.write (buffer [I]);
}
F0.close ();
Filewriter F1 = new filewriter ("file2.txt ");
F1.write (buffer );
F1.close ();
Filewriter F2 = new filewriter ("file3.txt ");
F2.write (buffer. Buffer. length-buffer.length/4, buffer. Length/4 );
F2.close ();
}
}