Here you can find the source of getFileByte(InputStream inputStream)
Parameter | Description |
---|---|
inputStream | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static byte[] getFileByte(InputStream inputStream) throws Exception
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { /**// w ww .j a v a 2s .c o m * * @param inputStream * @return * @throws Exception */ public static byte[] getFileByte(InputStream inputStream) throws Exception { InputStream fis = null; ByteArrayOutputStream sb = null; try { fis = inputStream; sb = new ByteArrayOutputStream(); byte[] bytes = new byte[128]; int n = -1; n = fis.read(bytes); while (n > -1) { sb.write(bytes, 0, n); n = fis.read(bytes); } byte[] rs = sb.toByteArray(); return rs; } catch (Exception e) { throw e; } finally { if (fis != null) { fis.close(); fis = null; } if (sb != null) { sb.close(); sb = null; } } } }