Seeking a ByteArrayInputStream using java.io

后端 未结 3 1631
误落风尘
误落风尘 2021-01-04 10:43

How can I seek (change the position) of a ByteArrayInputStream (java.io)? It is something so obvious, but I can\'t seem to find a method for this a

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-04 11:44

    You'd use reset()/skip(). I can't say it's the nicest API in the world, but it should work:

    public void seek(ByteArrayInputStream input, int position)
        throws IOException
    {
        input.reset();
        input.skip(position);
    }
    

    Of course, that assumes that no-one has called mark().

提交回复
热议问题