Difference
One is the Input/output stream system, one is the reader/writer system, the difference between the two is
Stream is responsible for the data of the byte stream, Reader/writer is responsible for the character stream.
Design mode decorator Mode
This mode is mainly used to continuously increase the subordinate function without changing the existing component design and code. Make a metaphor, like you have a picture, with one or more different frames.
For details, refer to here: http://www.cnblogs.com/bastard/archive/2012/02/02/2336150.html
Componnet to support the basic interface of decorator, which is what must be done at design time.
Both sets of IO systems are typical decorator models. The following article is an introduction to the relatively good.
http://my.oschina.net/gao0516/blog/136103
Adapter mode
This pattern is used to convert an object to an interface that can be used by another object. There are implementations within both systems. At the same time, the two modes of interconnection also rely on this model. There are two main classes:
InputStreamReader and OutputStreamWriter
From the name can be seen, both stream and reader/writer, a typical cross-system adapter.
For example, if you want to write a file with writer, the code is as follows:
static private void Test2 () { try { printwriter printwriter = new PrintWriter ("/home/dean/test2.log"); Printwriter.println ("Hello, China"); Printwriter.flush (); Printwriter.close (); } catch (IOException e) { System.out.println (e.getmessage ()); } }
After the run, the Test2.log file was created and there appeared a Hello, China.
However, there is a problem that the PrintWriter constructor does not accept the APPEND option, so each time the file is purged and re-written, the append write cannot be supported. and the stream system supports it. Therefore, the adapter model is used to mix the two systems.
static private void Test1 () { try { Writer w = new OutputStreamWriter (New FileOutputStream ("/home/dean/test1.log ", true)," UTF-8 "); PrintWriter printwriter = new PrintWriter (w); Printwriter.println ("Hello, China"); Printwriter.flush (); Printwriter.close (); } catch (IOException e) { System.out.println (e.getmessage ()); } }
Using the FileOutputStream support append features, with OutputStreamWriter do adapter, now can.
So it looks like the Reader/writer system features focus on text character processing, while the advanced functionality of some streaming operations relies on the mate of the stream system.
Java IO two major systems