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:
- F = new file ("D: // t. M ");
- Try {
- If (F. exists ())
- F. Delete ();
- F. createnewfile ();
- } Catch (IOException e1 ){
- // TODO Auto-generated catch block
- E1.printStackTrace ();
- }
When reading a file:
- If (! F. exists ())
- Return;