一、将byte数组转二进制流文件,并保存到本地
byte [] oneshotBytes=new byte[]{78,-29,51,-125,86,-105,56,82,-94,-115,-22,-105,0,-45,-48,-114,27,13,38,45,-24,-15,-13,46,88,-90,-66,-29,52,-23,40,-2,116,2,-115,17,36,15,-84,88,-72,22,-86,41,-90,-19,-58,19,99,-4,-63,29,51,-69,117,-120,121,3,-103,-75,44,64,-58,-34,73,-22,110,-90,92,-35,-18,-128,16,-36,41,23,-100,39,43,82,17,-64,62,-104,50,-72,71,68,50,-24,-75,-61,-15,-107,42,107,120,-48,41,81,9,-39,81,47,70,-63,-3,-54,69,-30,0,104,36,72,-57,67,-79,-67,-1,-64,-67,41,-99,-1,-60,-34,63,7,-104,99,-90,85,97,76,107,-124,79,39,-7,76,70,59,-126,98,9,102,3,122,7,66,10,-48,112,48,69,102,30,95,65,39,-9,88,109,-67,-29,-36,-11,86,-53,117,-68,96,-15,116,4,-69,115,53,35,30,115,-37,41,-75,119,-74,110,77,-116,-89,69,104,112,-22,-94,-84,-90,-90,-19,-121,-30,11,96,-125,-39,-114,-71,-123,27,68,-27,-85,72,-23,40,-100,33,107,88,-114,-118,-56,58,33,45,30,-119,-27,-58,111,-11,80,-111,-85,-10,120,-119,75,-10,1,71,-28,1,-26,50,-68,67,119,97,-41,-81,-7,-80,-17,-73,94,-61,65,-83,84,-16,70,-20,30,-91,-111,61,56,-99,113,0,50,-43,29,-81,-104,-90,81,-40,100,35,123,107,78,106,-61,38,-61,-124,78,25,-66,-16,-81,16,77,-88,58,-26,43,-50,28,-46,14,-75,76,64,-101,-26,92,-97,-106,-48,19,-6,-12,-102,91,42,-14,-26,95,50,67,113,-45,1,5,-98,118,-8,32,-74,-93,-66,0,99,-65,122,36,35,-53,-29,-116,50,19,-18,-14,-45,104,38,-47,79,-103,29,-44,-36,47,1,62,-12,-108,36,101,127,-19,63,15,-88,-85,97,-39,-26,-88,9,106,92,61,-109,-62,-96,-42,89,-123,-55,-69,76,-104,-20,24,-128,44,-76,-34,-85,40,-2,127,102,-100};
/**
* 创建File对象
*/
File file = new File(Environment.getExternalStorageDirectory(),
"test/streamFile");
// 创建FileOutputStream对象
FileOutputStream outputStream = null;
// 创建BufferedOutputStream对象
BufferedOutputStream bufferedOutputStream = null;
try {
// 如果文件存在则删除
if (file.exists()) {
file.delete();
}
// 根据路径创建一个新的空文件
file.createNewFile();
// 获取FileOutputStream对象
outputStream = new FileOutputStream(file);
// 获取BufferedOutputStream对象
bufferedOutputStream = new BufferedOutputStream(outputStream);
// 往文件所在的缓冲输出流中写byte数据
bufferedOutputStream.write(bytes);
// 输出流
bufferedOutputStream.flush();
} catch (Exception e) {
// 打印异常信息
e.printStackTrace();
} finally {
// 关闭创建的流对象
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bufferedOutputStream != null) {
try {
bufferedOutputStream.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
二、将二进制流文件从SDK卡中复制出来,打开postman:
①设置请求头,根据自己项目需要设置,注意Content-Type不要填写
②编辑发送内容,选择第一步生成的文件,如下: