
URL url = new URL("drop Box public share url"); //create the new connection httpURLConnection urlConnection = (httpURLConnection) url.openConnection(); urlConnection.setAllowUserInteraction(false); urlConnection.setInstanceFollowRedirects(true); urlConnection.setConnectTimeout(5 * 1000); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.setDoinput(true); urlConnection.connect(); file SDCardRoot = Environment.getExternalStorageDirectory(); file file = new file(SDCardRoot,"/download/sample.zip"); fileOutputStream fileOutput = new fileOutputStream(file); inputStream inputStream = urlConnection.getinputStream(); int totalSize = urlConnection.getContentLength(); int downloadedSize = 0; //create a buffer... byte[] buffer = new byte[1024]; int bufferLength = 0; while ( (bufferLength = inputStream.read(buffer)) > 0 ) { fileOutput.write(buffer,bufferLength); downloadedSize += bufferLength; onProgressUpdate(downloadedSize,totalSize); } //close the output stream when done fileOutput.close(); inputStream.close();解决方法 似乎方法调用: setDoOuput(true);
使请求成为POST(请参阅
What exactly does URLConnection.setDoOutput() affect?)
删除它似乎解决了这个问题.
总结以上是内存溢出为你收集整理的在android中下载Zip文件全部内容,希望文章能够帮你解决在android中下载Zip文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)