Differences between inputstream and reader in Java
Reader supports 16-bit Unicode character output, and inputstream supports 8-bit character output.
Reader and inputstream are two sets of parallel independent level organizations provided by the I/O database, respectively,
inputstream and outputstream are used to process 8-bit streams,
reader and writer are It is used to process a stream of 16 bits.
in Java, the byte type is 8-bit, And the char type is 16-bit. Therefore, you must use reader and writer to process Chinese characters.
it is worth noting that, under these two levels, there is also a bridge between inputstreamreader and outputstreamwriter to adapt inputstream to reader and from outputstream to writer.
Java. Io. Reader and Java. Io. inputstream constitute JAVA input classes. Reader is used to read 16 characters, that is, Unicode-encoded characters. inputstream is used to read ASCII characters and binary data.
In Java, different types of Reader Input streams correspond to different data sources:
Filereader is used for input from a file;
Chararrayreader is usedProgramCharacter array input in;
Stringreader is used to input strings from the program;
Pipedreader is used to read data written to the pipeline from pipedwriter in another thread.
Different types of inputstream input streams correspond to different data sources: fileinputstream, bytearrayinputstream, stringbufferinputstream, and pipedinputstream. In addition, there are two inputstream input streams that do not have the corresponding Reader Type:
Socket is used for sockets;
Urlconnection is used for URL Connection.
These two classes use getinputstream () to read data.
Correspondingly, there are similar differences between Java. Io. Writer and Java. Io. outputstream.