您的位置:首页 > 移动开发 > Android开发

android FileInputStream分段读取文件 断点续传

2016-10-17 14:48 946 查看
final Thread thread = new Thread() {
@Override
public void run() {
try {
File file = new File(path);
FileInputStream is = null;
// 获取文件大小
long length = file.length();
// 创建一个数据来保存文件数据
byte[] fileData = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int bytesRead=0;
// 读取数据到byte数组中
List<ByteArrayInputStream> temp = new ArrayList<>();
int len = 0;
fileData = new byte[1000*1000*2];
while((len=is.read(fileData))!=-1)
{
temp = new ArrayList<>();
ByteArrayInputStream byteArrayInputStream= new ByteArrayInputStream(fileData);
temp.add(byteArrayInputStream);
//上传流文件
RegisterControlService.submitVedioSon(
SubVedioViewActivity.this, temp, fInfos,subIdx);
temp.clear();
byteArrayInputStream.close();
subIdx++;
}
if(is != null)//完成后关闭输入流
is.close();
} catch (Exception ex) {
System.out.print(ex.toString()+"dujq");
String a = ex + "";
}
handler.post(callBack);
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: