By the two ways in which the previous bytes were entered, we can see that the array is read in a way that defines an array much faster than a byte read.
As a result, Java specifically provides a byte class with a buffer:
Buffer Class (Efficient Class)
Write Data : Bufferedoutputstream
Construction Method:
BufferedInputStream(InputStream in) 创建一个 BufferedInputStream 并保存其参数,即输入流 in,以便将来使用。
BufferedInputStream(InputStream in, int size)Creates a specified buffer size BufferedInputStream and saves its arguments, that is, the input stream for in future use.
Read Data : Bufferedinputstream
Construction Method:
BufferedOutputStream(OutputStream out) Creates a new buffered output stream to write data to the specified underlying output stream.
BufferedOutputStream(OutputStream out, int size) 创建一个新的缓冲输出流,以将具有指定缓冲区大小的数据写入指定的底层输出流。
Doubts:
Example: Bufferedoutputstream (OutputStream out)
Why not pass a specific file or file path, but pass a OutputStream object?
Reason:
Byte buffer streams provide only buffers and are designed for efficiency. However, the actual read and write operation is also dependent on the basic flow object implementation.
Example: Bufferedoutputstream: Equivalent to a water cup
OutputStream: Equivalent to water, quench your thirst and rely on water
Create an efficient byte output stream object and enter the data
New Bufferedoutputstream ( new fileoutputstream ("C.txt"));
Output data
Out.write ("Javaio". GetBytes ());
Out.close ();
Create a university byte input stream object and output the data
New Bufferedinputstream (new fileinputstream ( "Bos.txt"));
byte[] bys = new byte[1024];
int len = 0;
while (len = Bis.read (bys))! =-1) {
System.out.print (New String (bys, 0, Len));
}
Freeing resources
Bis.close ();
Java 20-9 byte output stream with buffer and byte input stream