1 import java.io.ByteArrayOutputStream;
 2 import java.io.InputStream;
 3 //从输入流中获取数据并以字节数组返回
 4 public class StreamTool {
 5     /**
 6      * 从输入流获取数据
 7      * @param inputStream
 8      * @return
 9      * @throws Exception
10      */
11     public static byte[] readInputStream(InputStream inputStream) throws Exception{
12         byte[] buffer = new byte[1024];
13         int len = -1;
14         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
15         while((len = inputStream.read(buffer)) != -1){
16             outputStream.write(buffer, 0, len);
17         }
18         outputStream.close();
19         inputStream.close();
20         return outputStream.toByteArray();
21     }
22 }

 

相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2022-12-23
  • 2021-11-14
猜你喜欢
  • 2021-06-11
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2021-05-17
相关资源
相似解决方案