有没有办法创建具有标记功能的 FileInputStream?
有没有可能的方法来创建 FileInputStream
并将支持的功能标记为 true
?
Is there any possible way to create FileInputStream
with mark supported feature as true
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将 Fileinputstream 包装在 BufferedInputStream 中。
缓冲流支持标记。
Wrap your Fileinputstream inside a BufferedInputStream.
The buffered streams support marks.
将其包装在
BufferedInputStream
。而不是
这样做:
并使用
bis
而不是fis
;您的代码中不需要更改任何其他内容。Wrap it in
BufferedInputStream
.instead of
do this:
and use
bis
instead offis
; nothing else should have to change in your code.BufferedInputStreams 并不神奇。它们仅支持与其底层缓冲区一样大的标记,并且这些缓冲区将占用内存。因此,如果您沿着这条路线走下去,那么了解用例并可能使用适当大小的缓冲区调用 BufferedInputStream 构造函数非常重要。如果底层文件开始变大并且您标记得足够远,那么此技术可能不适合您。
BufferedInputStreams are not magic. They will only support marking for as large as their underlying buffers and these buffers are going to take up memory. So if you go down this route its important that you understand the usage case and potentially call the BufferedInputStream constructor with the appropriatedly sized buffer. If the underlying file starts to get large and you mark far enough back then this technique may not work for you.
尝试这样的事情
Try something like this