ここにコードがあります
byte data[] = new byte[1024];
fout = new FileOutputStream(fileLocation);
ByteBuffer bb = ByteBuffer.allocate(i+i); // i is size of download
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
while( (dat = rbc.read(bb)) != -1 )
{
bb.get(data);
fout.write(data, 0, 1024); // write the data to the file
speed.setText(String.valueOf(dat));
}
このコードでは、特定の URL からファイルをダウンロードしようとしていますが、ファイルは完全にはダウンロードされません。
どのようなエラーが発生したのかわかりません。ReadableByteChannel のせいですか? または、バイトを ByteBuffer から Byte[] に正しく配置しませんでした。