看板 AndroidDev 關於我們 聯絡資訊
※ 引述《mib30213 (夏天來了)》之銘言: : 我想要讀入一個未知大小的檔案, : 並讀入buffer ,分成4MB 為一個byte array : 該怎麼寫會比較好!?卡關卡很久 : FileInputStream fileInputStream = null; : FileOutputStream fileOutputStream = null; : byte[] buffer = new byte[available()]; : while((length = fileInputStream.read(buffer)) != -1) { : // 將陣列資料寫入目的檔案 : fileOutputStream.write(buffer, 0, length); : } while((length = fileInputStream.read(buffer)) > 0) { fileOutputStream.write(buffer, 0, length); } fileInputStream.close(); fileOutputStream.close(); 像這種需求我都用apache commons-io裡面的 IOUtils.copy(in, out); 簡單又正確 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.250.189.213