流转二进制
1 public static byte[] toByteArray(InputStream in) throws IOException { 2 ByteArrayOutputStream out=new ByteArrayOutputStream(); 3 byte[] buffer=new byte[1024*4]; 4 int n=0; 5 while ( (n=in.read(buffer)) !=-1) { 6 out.write(buffer,0,n); 7 } 8 return out.toByteArray(); 9 }
二进制转流
1 public static byte[] toInputStream(byte[] b) throws IOException { 2 returnInputStream inputStream = new ByteArrayInputStream(b); 3 }