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