Android 照片文件转化为而二进制流

/**
 * 照片转byte二进制
 * @param imagepath 需要转byte的照片路径
 * @return 已经转成的byte
 * @throws Exception
 */
public static byte[] readStream(String imagepath) throws Exception {
FileInputStream fs = new FileInputStream(imagepath);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while (-1 != (len = fs.read(buffer))) {
outStream.write(buffer, 0, len);
}
outStream.close();
fs.close();
return outStream.toByteArray();
} 



  params.add("img", String.valueOf(readStream(img)));


你可能感兴趣的:(安卓类)