(Memories from last season:
An instantiation scheme of System.out--gtrintStream, which has the function of printing to the screen, and later explained the examples that can be output to the screen using the OutputStream class.
Program this season:
1. System.in
2. Buffer stream
3. Program serialization
System.in corresponds to keyboard input
publicstaticfinalInputStreamin
It's just that instead of reading from the file as before, the data is read from the keyboard.
Take a look at the effect:
Although the above program can input content, there is a problem:
The main program opened up a space, what if the input content is now larger than the space opened?
Take a look at the effect:
If the length is greater than the set length, there must be content that cannot be read in. The best way is to not set the length, and continue reading if there is content.
Take a look at the effect:
There is indeed no limit to the length of adopting the judgment of whether the method of reading the end is the end, but there is also another problem. If you input Chinese, it must appear garbled?
The best way to manage it is to set up a buffer and put everything into the buffer and read it out at once.
This buffer is preferably a character buffer - BufferedReader
publicBufferedReader(Readerin)
It is necessary to receive a Reader scheme here, but System.in is actually a scheme of the InputStream class
Byte to character stream conversion
redking.blog.51cto/attachment/200903/1/27212_1235916759MxZ7.png
Reader and Writer themselves use buffering: Writer--gt;OutputStreamWriter--gt;FileWriter
Conclusion:
Physically registered must always be bytes
·The character stream will be formed when the program is read
Code pattern to derive complete input data:
Now look at the final effect:
redking.blog.51cto/attachment/200903/1/27212_1235916772NsEi.png
The above is the standard format, we now use this format to terminate a function, input two integers and then calculate the addition result of the two numbers.
character set
GBK: is a font library including Simplified Chinese and Traditional Chinese
GB2312: is a font library that only includes simplified Chinese
ISO8859-1: is a universal code for the world
There is a default encoding method in the system.
What if you know the default code of the system at that time? Then look at the following~
The default encoding method is GBK, then ask, if the current system encoding is GBK, and I use ISO encoding, can you explain it accurately?
How to manage the garbled characters - the same as the encoding set by the system is OK.
SequenceInputStream class
redking.blog.51cto/attachment/200903/1/27212_1235916830uB4l.png
SequenceInputStream for file merging
redking.blog.51cto/attachment/200903/1/27212_12359168447WXI.png
Take a look at the effect after the merger:
redking.blog.51cto/attachment/200903/1/27212_1235916850DRfb.png
Scheme serialization
redking.blog.51cto/attachment/200903/1/27212_1235916867IExy.png
There are actually two classes used:
·ObjectOutputStream
·ObjectInputStream
The role of the Serializable interface:
Just an identifying interface, indicating that the scheme of your class is allowed to be serialized
The structure method of the ObjectOutputStream class receives an instantiation scheme of the OutputStream class to indicate exactly where to save.
publicfinalvoidwriteObject(Objectobj) throwsIOException
Structure method of ObjectInputStream class
publicfinalObjectreadObject() throwsIOException, ClassNotFoundException
redking.blog.51cto/attachment/200903/1/27212_1235916872LwYu.png
redking.blog.51cto/attachment/200903/1/27212_1235916885SC54.png
redking.blog.51cto/attachment/200903/1/27212_1235916899TXg4.png
Deserialize below (restore scheme from file)
redking.blog.51cto/attachment/200903/1/27212_12359169189i5h.png
Look at the effect: read the scheme from the file
redking.blog.51cto/attachment/200903/1/27212_1235916920S9NO.png
Schema serialization actually refers more precisely to the fact that the schema can be turned into bytes.
transient keyword
When a field in a class is not expected to be serialized, use transient to indicate this field
redking.blog.51cto/attachment/200903/1/27212_1235916930bFOD.png
Take a look at the effect:
redking.blog.51cto/attachment/200903/1/27212_1235916932I6F1.png
Summarize
OutputStream: byte output stream class
-FileOutputStream
-ObjectOutputStream
-ByteArrayOutputStream
-PipedOutputStream
-PrintStream
InputStream: byte input stream class
-FileInputStream
-ObjectInputStream
-ByteArrayInputStream
-PipedInputStream
Reader: Input class for character streams
-InputStreamReader
-FileReader
-BufferedReader
Writer: Output class for character streams
-OutputStreamWriter
-FileWriter
-PrintWirer
File class:
Serializable interface
################################################## #####)