一、將byte數(shù)組轉(zhuǎn)二進制流文件,并保存到本地
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};
?
? ? ? ? /**
? ? ? ? ?* 創(chuàng)建File對象
? ? ? ? ?*/
? ? ? ? File file = new File(Environment.getExternalStorageDirectory(),
? ? ? ? ? ? ? ? "test/streamFile");
? ? ? ? // 創(chuàng)建FileOutputStream對象
? ? ? ? FileOutputStream outputStream = null;
? ? ? ? // 創(chuàng)建BufferedOutputStream對象
? ? ? ? BufferedOutputStream bufferedOutputStream = null;
? ? ? ? try {
? ? ? ? ? ? // 如果文件存在則刪除
? ? ? ? ? ? if (file.exists()) {
? ? ? ? ? ? ? ? file.delete();
? ? ? ? ? ? }
? ? ? ? ? ? // 根據(jù)路徑創(chuàng)建一個新的空文件
? ? ? ? ? ? file.createNewFile();
? ? ? ? ? ? // 獲取FileOutputStream對象
? ? ? ? ? ? outputStream = new FileOutputStream(file);
? ? ? ? ? ? // 獲取BufferedOutputStream對象
? ? ? ? ? ? bufferedOutputStream = new BufferedOutputStream(outputStream);
? ? ? ? ? ? // 往文件所在的緩沖輸出流中寫byte數(shù)據(jù)
? ? ? ? ? ? bufferedOutputStream.write(bytes);
? ? ? ? ? ? // 輸出流
? ? ? ? ? ? bufferedOutputStream.flush();
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? // 打印異常信息
? ? ? ? ? ? e.printStackTrace();
? ? ? ? } finally {
? ? ? ? ? ? // 關(guān)閉創(chuàng)建的流對象
? ? ? ? ? ? if (outputStream != null) {
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? outputStream.close();
? ? ? ? ? ? ? ? } catch (IOException e) {
? ? ? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? if (bufferedOutputStream != null) {
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? bufferedOutputStream.close();
? ? ? ? ? ? ? ? } catch (Exception e2) {
? ? ? ? ? ? ? ? ? ? e2.printStackTrace();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
二、將二進制流文件從SDK卡中復(fù)制出來,打開postman:
①設(shè)置請求頭,根據(jù)自己項目需要設(shè)置,注意Content-Type不要填寫
②編輯發(fā)送內(nèi)容,選擇第一步生成的文件,如下:
文章來源:http://www.zghlxwxcb.cn/news/detail-618458.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-618458.html
到了這里,關(guān)于將數(shù)據(jù)轉(zhuǎn)二進制流文件,用PostMan發(fā)送二進制流請求的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!