retrofit下载大文件注意点和android存储位置
2017-01-19 13:09
375 查看
1.retrofit下载大文件需要注意的点:(1)下载代码
try{ int fileSize = mAttachmentFiles.get(index).getFileSize(); InputStream inputStream = null; OutputStream outputStream = null; int fileSizeDownloaded = 0; inputStream = body.byteStream(); try { byte[] fileReader = new byte[2048]; outputStream = new FileOutputStream(file); while (true) { int read = inputStream.read(fileReader); if (read == -1) { mHandler.sendEmptyMessage(-1); turnByIntent(); break; } outputStream.write(fileReader, 0, read); fileSizeDownloaded += read; int num =(int) (((float)fileSizeDownloaded/ (float) fileSize)*100); Message msg = mHandler.obtainMessage(); msg.arg1 = num; mHandler.sendMessage(msg); } outputStream.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } } } catch (IOException e) { e.printStackTrace(); }(2)@Streaming,不能丢,亲测,不加这个注解,会报oom.
2.andoid存储目录:
//Context.getExternalFilesDir() --> SDCard/Android/data/你的应用的包名/files/ 目录,一般放一些长时间保存的数据9287//Context.getExternalCacheDir() --> SDCard/Android/data/你的应用包名/cache/目录,一般存放临时缓存数据getCacheDir()方法用于获取/data/data/<application package>/cache目录getFilesDir()方法用于获取/data/data/<application package>/files目录
相关文章推荐
- APK 变成 ZIP:Android 手机应用程序文件下载服务器需要注意的问题
- APK 变成 ZIP:Android 手机应用程序文件下载服务器需要注意的问题
- android-async-http下载zip文件存储或解压
- Android仿电脑端选择文件存储位置实例
- Android Retrofit文件下载进度显示问题的解决方法
- Android开发九:从网上下载文件并存储到SD卡中
- android文件存储位置切换
- 腾讯对象存储服务COS加密签名上传文件与下载文件的剖析,福利提供给所有使用Android的小伙伴们!
- Android文件存储位置简述
- ssh上传文件下载文件命令--------sz与rz命令----注意设置文件存储的路径!!!
- APK 变成 ZIP:Android 手机应用程序文件下载服务器需要注意的问题
- android文件存储位置切换
- APK 变成 ZIP:Android 手机应用程序文件下载服务器需要注意的问题
- Android Retrofit2.0实现文件上传和下载
- Android从网上下载文件注意
- Android下载文件需要注意的问题
- APK 变成 ZIP:Android 手机应用程序文件下载服务器需要注意的问题
- .FileNotFoundExceptionAndroid中的文件存储位置
- java文件下载以及服务器文件存储位置获取和存储位置
- Android中的文件存储位置分析