你可以
org.apache.commons.io.IOUtils.copy用来将
InputStream的内容复制到字节数组,然后使用
ByteArrayInputStream从字节数组重复读取。例如:
ByteArrayOutputStream baos = new ByteArrayOutputStream();org.apache.commons.io.IOUtils.copy(in, baos);byte[] bytes = baos.toByteArray();// eitherwhile (needToReadAgain) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); yourReadMethodHere(bais);}// orByteArrayInputStream bais = new ByteArrayInputStream(bytes);while (needToReadAgain) { bais.reset(); yourReadMethodHere(bais);}


