假设您正在使用HTTP进行下载,则需要使用HEAD http动词和RANGE http标头。
HEAD将为您提供文件大小(如果可用),然后RANGE可让您下载字节范围。
有了文件大小后,将其分成大小大致相等的块,并为每个块生成下载线程。完成所有操作后,以正确的顺序写入文件块。
如果您不知道如何使用RANGE标头,这里是另一个SO答案,说明了如何:http://codingdict.com/questions/131429
[编辑]
为了使文件成块,请使用它并开始下载过程,
private void getBytesFromFile(File file) throws IOException { FileInputStream is = new FileInputStream(file); //videorecorder stores video to file java.nio.channels.FileChannel fc = is.getChannel(); java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocate(10000); int chunkCount = 0; byte[] bytes; while(fc.read(bb) >= 0){ bb.flip(); //save the part of the file into a chunk bytes = bb.array(); storeByteArrayToFile(bytes, mRecordingFile + "." + chunkCount);//mRecordingFile is the (String)path to file chunkCount++; bb.clear(); }}private void storeByteArrayToFile(byte[] bytesToSave, String path) throws IOException { FileOutputStream fOut = new FileOutputStream(path); try { fOut.write(bytesToSave); } catch (Exception ex) { Log.e("ERROR", ex.getMessage()); } finally { fOut.close(); }}


