Java InputStream size

后端 未结 4 1636
醉酒成梦
醉酒成梦 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:41

    It isn't knowable in principle (consider a peer that never stops writing), and you don't need it. Just read and write in a loop using a fixed size buffer. NIO doesn't offer any magical solution.

提交回复
热议问题