作者popcorny (毕业了..@@")
看板AndroidDev
标题Re: [问题] 读档到buffer
时间Tue Jun 4 22:10:41 2013
※ 引述《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