"JAVA io stream character stream"

Source: Internet
Author: User

I. Overview.

Java's operations on data are streamed.
The objects that Java uses to manipulate the flow are all in the IO package.
The flow is divided into two types, byte stream and character stream according to operational data.
Streams are divided into input streams and output streams according to flow direction.

The "in" and "out" of the input and output are equivalent to memory.

Character stream: After the byte stream reads the text bytes data, does not direct operation, but first checks the specified encoding table, obtains the corresponding text, then carries on the operation to this text. In simple terms, it's a byte-stream + code table.

In the IO stream, the top-level parent class of the byte stream is writer and reader.

Second, the Java.io.FileWriter class.

FileWriterextends OutputStreamWriter

Writer

|--outputstreamwriter

|--filewriter

This class is a stream of manipulating character files that are used to write data to a file.

1. Construction method.

There are two important construction methods:

FileWriter(File file)
Constructs a FileWriter object based on the given File object.
FileWriter(File file, boolean append)
Constructs a FileWriter object based on the given File object.

The latter has a Boolean parameter relative to the former, which determines whether the file is written in either append or overwrite mode.

The default constructor method (the former) constructs a filewriter stream object that writes to the file by default, emptying and then writing the contents of the file, and if the latter is used and the true is passed to the constructor, the way it is written becomes an append method.

2.write method.

The class does not have its own write method, all inherited from the parent class or superclass.

Methods inherited from OutputStreamWriter:

void Write (char[] cbuf, Int off, Int len)
            writes a portion of a character array.
  ; void write (int c)
            writes a single character.
  ; void Write (string str, Int off, Int len)
           writes a portion of a string.

The Write method inherited from writer:

 void write(char[] cbuf)
Writes an array of characters.
 void write(String str)
Writes a string.

3.flush method.

void flush()
Refreshes the buffer of the stream.

This method is inherited from the OutputStreamWriter, and is used to brush data from the stream into a file. This method is called by default before the file is closed.

4.close method.

 void close()
Close the stream, but refresh it first.

"JAVA io stream character stream"

Related Article

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.