Custom BufferedReader instance
The purpose of buffer establishment is to increase the transmission performance and make us transmit data faster
The inside of the buffer is actually very simple. It encapsulates an array inside, uses the array to store data, and provides some methods to access the array
The operation of these methods is the pointer (subscript) to the array.
Principle of buffer: get a batch of data from the source to the buffer, take it out one by one from the buffer, and then use - 1 as the end mark
In BufferedReader, we read data by read(), readline()
Read() whose parameters are char [], cbuf, int off, int len. The return value is - 1
The readLine () method is fetched line by line. Its interior is like a string container StringBuffer, and its return value is null;
First, define a class, and define two data reading methods myreader(), myreadline();
In it, I define the pointer ZZ and a buffer counter count to record the changes of data read in the buffer
When count = = 0, data is read into the buffer, ZZ is 0, and it is read from the first number
When less than 0, the data is read and - 1 is returned
Create a string container StringBuilder in myreadline() to store data. When STB = = \ n a line is read, its return value is null;
The above example of user-defined BufferedReader is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.