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"