public void saveBit(InputStream inStream) throws IOException{
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
//創建一個Buffer字符串
byte[] buffer = new byte[1024];
//每次讀取的字符串長度,如果為-1,代表全部讀取完畢
int len = 0;
//使用一個輸入流從buffer里把數據讀取出來
while( (len=inStream.read(buffer)) != -1 ){
//用輸出流往buffer里寫入數據,中間參數代表從哪個位置開始讀,len代表讀取的長度
outStream.write(buffer, 0, len);
}
//關閉輸入流
inStream.close();
//把outStream里的數據寫入內存
//得到圖片的二進制數據,以二進制封裝得到數據,具有通用性
byte[] data = outStream.toByteArray();
//new一個文件對象用來保存圖片,默認保存當前工程根目錄
File imageFile = new File("E:/BeautyGirl.jpg");
//創建輸出流
FileOutputStream fileOutStream = new FileOutputStream(imageFile);
//寫入數據
fileOutStream .write(data);
}