从服务器下载文件的方法
2012-03-21 15:34
302 查看
public static void downFile(String url,Context cxt) throws Exception{ HttpClient client=new DefaultHttpClient(); HttpPost post=new HttpPost(url); InputStream res=null; BufferedOutputStream bos = null; BufferedInputStream bis=null; ZipInputStream zis=null; ZipEntry entry=null; HttpEntity entity=null; try{ HttpResponse response = client.execute(post); if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){ entity= response.getEntity(); res=entity.getContent(); } FileUtils.deleteFiles(cxt.getFilesDir()); bis = new BufferedInputStream(res); zis= new ZipInputStream(bis); while ((entry = zis.getNextEntry()) != null) { int count; byte data[] = new byte[2048]; bos = new BufferedOutputStream(cxt.openFileOutput(entry.getName(), Context.MODE_WORLD_READABLE|Context.MODE_WORLD_WRITEABLE)); while ((count = zis.read(data)) != -1) { bos.write(data, 0, count); } bos.flush(); data=null; } }catch(Exception ex){ ex.printStackTrace(); }finally{ Log.e("downFile", "downFile_finally"); zis.close(); bis.close(); bos.close(); res.close(); entity.consumeContent(); client.getConnectionManager().shutdown(); entry=null; zis=null; bis=null; bos=null; client=null; post=null; cxt=null; } }
相关文章推荐
- 让WIN2003和2008服务器iis支持安卓应用.apk文件下载的配置方法
- 从服务器下载指定文件的标准方法
- win2003服务器允许下载.exe文件的方法
- jsp实现从服务器下载xls文件到客户端的方法
- python实现从ftp服务器下载文件的方法
- 让服务器iis支持.apk文件下载的设置方法
- 让服务器iis支持.apk文件下载的设置方法
- java方法客户端下载服务器上的文件到本地
- 让服务器iis支持.apk文件下载的设置方法
- 让服务器iis支持.apk文件下载的设置方法
- 如何让服务器支持mp4文件下载和sqlserver将表生成为sql语句方法
- web端下载服务器上的文件,js方法下载
- nginx服务器在IE下载时,apk文件变成zip的解决方法(转)
- Java通过FTP服务器上传下载文件的方法
- javascript+C#下载服务器文件到本地方法
- 服务器iis支持.apk文件下载的设置方法
- 从服务器下载文件方法的实际应用
- JSP实现从不同服务器上下载文件的方法
- php实现远程网络文件下载到服务器指定目录(方法一)
- 让服务器iis支持.apk文件下载的设置方法