Byte stream, character stream inheritance relationship
The previous articles explain the use of byte stream, character stream, but Java provides users with a stream class far more than this, limited to the length of reason, no way one by one explanation, and there is no need to explain one by one, as I wrote in the time of the blog repeatedly mentioned, there are problems when learning to check the JDK API can . OK, while not explaining each stream, I drew a few UML diagrams myself, explaining the subclass inheritance relationships of the four stream classes, byte input stream, byte output stream, character input stream, character output stream.
1, byte input stream
2, byte output stream
3. Character input stream
4. Character output stream
Summarize the use of flow classes
1, file is the source of some files/folders operations, file represents the files/folders themselves, so in any case, the first step in using IO is to suggest that the developer based on the path to instantiate a file
2. Consider the use of character streams or bytes. The operation text generally uses a character stream, that is, reader and writer; manipulate byte files using a stream of bytes, i.e. InputStream and OutputStream
3. Choose whether to use an input stream or an output stream. Reads the content from the file into Java memory using the input stream, reader and InputStream, and reads the content from Java memory to the file using the output stream, which is writer and outputstream
4. Using BufferedReader and bufferedwriter with character streams, the parameters in their constructors are reader and writer, so that both FileReader and FileWriter can be instantiated. You can also instantiate InputStreamReader and OutputStreamWriter, which are passed into BufferedReader and bufferedwriter as arguments to the constructor.
5, FileInputStream and FileOutputStream can directly manipulate the file read and write, they do not cache
6, ObjectOutputStream and ObjectInputStream, respectively, with OutputStream and InputStream as the parameters of the constructor function, Therefore, FileOutputStream and FileInputStream can be instantiated and passed
Also, please be aware that IO is a typical application of the adorner pattern in the 23 design modes of Java , which will be described when explaining design patterns.
Java Io8:io Simple Summary