Dark Horse Programmer-Learn notes character stream related

Source: Internet
Author: User
Tags try catch

1.FileWriter

FileWriter FW = new FileWriter ("Demo.txt");

Fw.writer ("ABCDE");
Fw.flush ();
Fw.close ();

The writer () method simply writes the data to the memory (stream);
Flush (): The data in the current stream is brushed into the destination (demo.txt).

If the FW (stream) is not closed, write the data repeatedly using the writer () method.

Close (): Closes this stream, but refreshes the data in the cache first.

Flush () and close (): Flush () After execution, the current stream can continue to be used, and close () Z will close the stream after execution.

2.IO Exception Handling methods

Either read or write, as long as the resource on the operating device can produce an exception.

Creates a reference outside and initializes it in a try catch block. As follows:
FileWriter FW = NULL;
try{
FW = new FileWriter ("D:\\demo.txt");
}

Full IO exception handling process:

NULL ; Try  New FileWriter ("D:\\demo.txt");} Catch (ioexcetption e) {e.printstacktrace ();} finally {  try  {  if(null !=catch(  Ioexcetption e) {e.printstacktrace (); }}

Dark Horse Programmer-Learn notes character stream related

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.