How to Cache InputStream for Multiple Use

后端 未结 10 1022
庸人自扰
庸人自扰 2020-11-29 05:57

I have an InputStream of a file and i use apache poi components to read from it like this:

POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream);
         


        
10条回答
  •  北海茫月
    2020-11-29 06:38

    public static void main(String[] args) throws IOException {
        BufferedInputStream inputStream = new BufferedInputStream(IOUtils.toInputStream("Foobar"));
        inputStream.mark(Integer.MAX_VALUE);
        System.out.println(IOUtils.toString(inputStream));
        inputStream.reset();
        System.out.println(IOUtils.toString(inputStream));
    }
    

    This works. IOUtils is part of commons IO.

提交回复
热议问题