Re: [問題] 讀檔到buffer

看板AndroidDev作者 (畢業了..@@")時間12年前 (2013/06/04 22:10), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/4 (看更多)
※ 引述《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
文章代碼(AID): #1HhVLZLi (AndroidDev)
討論串 (同標題文章)
文章代碼(AID): #1HhVLZLi (AndroidDev)