How to Skip Bytes in a BufferedInputStream in Java
The correct answer is 'OB skip'.
The skip() method in BufferedInputStream is specifically designed to skip a certain number of bytes in the input stream. It allows you to efficiently move the stream's position forward without reading the data.
Here's how it works:
BufferedInputStream bis = new BufferedInputStream(inputStream);
long bytesToSkip = 100; // Number of bytes to skip
long skippedBytes = bis.skip(bytesToSkip);
In this example, the skip() method attempts to skip bytesToSkip bytes. The return value, skippedBytes, indicates the actual number of bytes skipped. It might be less than bytesToSkip if the end of the stream is reached before skipping all the desired bytes.
Other options:
- 'OA mark': The
mark()method is used to mark the current position in the stream for later retrieval usingreset(). It doesn't skip bytes. - 'Oc reset': The
reset()method restores the stream's position to the previously marked location. It doesn't skip bytes. - 'OD close': The
close()method closes the stream and releases any associated resources. It doesn't skip bytes.
原文地址: https://www.cveoy.top/t/topic/oANv 著作权归作者所有。请勿转载和采集!