Filewriter Class Example

Source: Internet
Author: User
/* 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 ();
}
}

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.