大佬教程收集整理的这篇文章主要介绍了Resume下载在Android中不工作,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
BufferedInputStream in = null; FiLeoutputStream fos = null; bufferedoutputstream bout=null; try { downloaded=0; httpURLConnection connection = (httpURLConnection) url.openConnection(); if(ISSUE_DOWNLOAD_STATUs.intValue()==ECMConstant.ECM_DOWNLOADING){ File file=new File(DESTinATION_PATH); if(file.exists()){ downloaded = (int) file.length(); } } connection.setrequestProperty("Range","bytes=" + downloaded + "-"); connection.connect(); size=connection.getContentLength(); Dialog.setMax(sizE); in = new BufferedInputStream(connection.geTinputStream()); fos=(downloaded==0)? new FiLeoutputStream(DESTinATION_PATH): new FiLeoutputStream(DESTinATION_PATH,truE); bout = new bufferedoutputstream(fos,1024); byte[] data = new byte[1024]; int x = 0; while ((x = in.read(data,1024)) >= 0) { bout.write(data,X); downloaded += x; System.out.println(downloaded); onProgressupdate((int)(downloaded*100/sizE)); } succes=true; } catch (Exception E) { e.printStackTrace(); } finally { try { in.close(); bout.close(); } catch (IOException E) { e.printStackTrace(); } }
谢谢.
httpURLConnection connection = (httpURLConnection) url.openConnection(); int buf = 1024; if (ISSUE_DOWNLOAD_STATUs.intValue() == ECMConstant.ECM_DOWNLOADING) { File file = new File(DESTinATION_PATH); if (file.exists()) { downloaded = (int) file.length(); connection.setrequestProperty("Range","bytes=" + file.length() + "-"); } } else { connection.setrequestProperty("Range","bytes=" + downloaded + "-"); } connection.setDoInput(true); connection.setDoOutput(true); progressBar.setMax(connection.getContentLength()); in = new BufferedInputStream(connection.geTinputStream()); fos = new FiLeoutputStream(DESTinATION_PATH,downloaded == 0 ? false : truE); bout = new bufferedoutputstream(fos,buf); byte[] data = new byte[buf]; while ((int x = in.read(data,buf)) >= 0) { bout.write(data,X); downloaded += x; progressBar.setProgress(downloaded); }
以上是大佬教程为你收集整理的Resume下载在Android中不工作全部内容,希望文章能够帮你解决Resume下载在Android中不工作所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。