input byte 互轉

  1. private byte[] InputStreamToByte(InputStream is) throws IOException {  
  2.    ByteArrayOutputStream bytestream = new ByteArrayOutputStream();  
  3.    int ch;  
  4.    while ((ch = is.read()) != -1) {  
  5.     bytestream.write(ch);  
  6.    }  
  7.    byte imgdata[] = bytestream.toByteArray();  
  8.    bytestream.close();  
  9.    return imgdata;  
  10.   }  

 

byte[]轉InputStream

 

Java代碼  收藏代碼
  1. byte[] data;  
  2. InputStream is = new ByteArrayInputStream(data);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章