Java InputStream size

后端 未结 4 1638
醉酒成梦
醉酒成梦 2020-12-19 06:03

I need to get the size in bytes of an InputStream without creating a File instance. Is there any way to do it using Java NIO?

4条回答
  •  甜味超标
    2020-12-19 06:49

    A couple of additional options:

    Depending on the blocking nature of the input stream, you could call available() on the stream.

    If the streams are smallish, you could write them into PushbackInputStreams, count the bytes and then rewind.

提交回复
热议问题