Java IO stream

Source: Internet
Author: User

Io streams are used to process data transmission between devices.

Java operates data through a stream

Java operation flow objects are all in the IO package

Streams are divided into byte streams and byte streams by operation data.

Streams are divided into input streams and output streams by flow.

Byte stream abstraction base class: inputstream, outputstream

Extract stream abstract base class: reader and writer

The above four classes are derived from common subclasses: fileinputstream, fileoutputstream, filereader, and filewriter.

Ghost stream

FileWriter fw = null;fw = new FileWriter("D:\\test.txt");fw.write("test");if (fw != null) fw.close();

Common Code segments:

When writing a file:

  1. F = new file ("D: // t. M ");
  2. Try {
  3. If (F. exists ())
  4. F. Delete ();
  5. F. createnewfile ();
  6. } Catch (IOException e1 ){
  7. // TODO Auto-generated catch block
  8. E1.printStackTrace ();
  9. }

When reading a file:

  1. If (! F. exists ())
  2. Return;

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.