android下载文件下载不完全解决方案
2015-11-05 10:17
736 查看
最近在弄android下载文件,总是发现下载的文件大小比服务器端传递过来的size要偏小。在网上查了许多相关的资料,大多数都认为需要设置一下获取服务器端文件时的参数:HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection();
httpURLConnection.setRequestProperty("Accept-Encoding", "identity");
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
int contentLength = httpURLConnection.getContentLength();
也就是需要新增httpURLConnection.setRequestProperty("Accept-Encoding", "identity");这一行,我测试了,新增了这一行后获取的word文档没有乱码的情况了,看了下载的文件大小和服务器端传递过来的size一样大了。这个方法仅供参考,可能也有不足,希望有新的见解的人和我相互交流一下
.openConnection();
httpURLConnection.setRequestProperty("Accept-Encoding", "identity");
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
int contentLength = httpURLConnection.getContentLength();
也就是需要新增httpURLConnection.setRequestProperty("Accept-Encoding", "identity");这一行,我测试了,新增了这一行后获取的word文档没有乱码的情况了,看了下载的文件大小和服务器端传递过来的size一样大了。这个方法仅供参考,可能也有不足,希望有新的见解的人和我相互交流一下
相关文章推荐
- UNICODE本地编译freescale的i.MX6Q的android4.2.2&android4.4.2 && 全志a80的步骤x1
- Android bootchart(二)
- android textview原生态跑马灯效果实现以及其缺点记录
- Android的四种启动模式和onNewIntent()
- Android studio提交代码到Git@OSC
- android开发问题
- Android开发常见问题汇总
- Android开发总结笔记 ScrollView和HorizontalScrollView (滚动视图) 1-3-5
- 通过UserAgent判断智能手机(设备,Android,IOS)
- Android开发常见错误汇总
- 【android】PopWindow----还没有更完
- Android GPS学习笔记(6)—GpsLP初始化
- Android GPS学习笔记(5)—LMS初始化
- Android GPS学习笔记(4)—HAL实现
- Android GPS学习笔记(3)—JNI层实现
- startActivityForResult和setResult
- Android Studio + Genymotion安卓模拟器打造高效安卓开发环境
- Android GPS学习笔记(2)—重要结构体及接口
- Android开发TextView实现长按复制文本功能的方法
- Android中 Bitmap和Drawable相互转换的方法