1.FileWriter class
The inflow and outflow of Io stream is based on the Java program, and enters the program as input, and the program is output.
1.1. Construction method
FileWriter class
Construction method |
Parameters |
Description |
Public FileWriter (String fileName) |
Represents the system-related file name |
Constructs a FileWriter object based on the given file name. |
Public FileWriter (String fileName, Boolean append) |
Append if True, data is written to the end of the file |
|
1.2. Member Methods
FileWriter class
Parent class Inheritance |
Member Methods |
Parameters |
Description |
Java.io.Writer; |
public void Write (String str) |
STR is the string to write to |
Constructs a FileWriter object based on the given file name. |
Java.io.OutputStreamWriter |
public void Flush () |
|
Refreshes the buffer of the stream object |
Java.io.OutputStreamWriter |
public void Close () |
|
Close Stream Object |
Java.io.OutputStreamWriter |
Public String getencoding () |
|
Returns the character encoding name used by the stream |
Simple example: Save "Hello World" to a file. A string that does not exist when the file is created, overwriting The original file content when the file exists.
1 FileWriter fw = new FileWriter (" Ioflow.txt " 2 fw.write ("Hello" 3 fw.write ("" 4 fw.write ("World" 5 fw.write ("." 6 7 Fw.flush (); 8 String encode = fw.getencoding (); 9 System.out.println (encode); // GBK 10 fw.close ();
After the stream is closed, the GetEncoding () method is called, and Null is returned.
1 fw.close (); 2 encode = fw.getencoding (); 3 System.out.println (encode); // NULL
IO stream for Java