public static byte[] input2byte(InputStream inStream) throws IOException {
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[inStream.available()];
方法1:
/* int rc = 0;
while ((rc = inStream.read(buff, 0, inStream.available())) > 0) {
swapStream.write(buff, 0, rc);
}*/
方法2:
int rc = 0;
while((rc = inStream.read(buff))!=-1){
swapStream.write(buff, 0, rc);
}
byte[] in2b = swapStream.toByteArray();
swapStream.close();
return in2b;
}
原文:http://blog.51cto.com/1008610086/2350390