java.io.IOException: mark/reset not supported 异常
Problem statement:
The given stream does not support mark
and reset
operation
problem analysis:
mark
The reset
sum operation requires the input stream to be able to move the read/write head back and forth. Generally, the input stream is read and written in the buffer, but the InpurStream
input stream has no buffer, so the sum mechanism is InputStream
not allowedmark
reset
problem solved:
Since mark
the AND reset
operation requires the input stream to have a buffer, and because BufferedInputStream
it inherits from FilterInputStream
, it provides the function of buffering the input stream, so it can InpurStream
be packaged BufferedInputStream
.
code:
// 定义一个输入流
InputStream is = null;
// 将 InputStream 输入流打包成 BufferedInputStream
BufferedInputStream bfi = new BufferedInputStream(is);