安卓下载保存到本地(一)
来源:互联网 发布:淘宝店被扣48分怎么办 编辑:程序博客网 时间:2024/06/11 18:51
public void getFileFromServer(String path) throws Exception{
HttpClient client = new DefaultHttpClient();
// params[0]代表连接的url
HttpGet get = new HttpGet(path);
HttpResponse response;
response = client.execute(get);
HttpEntity entity = response.getEntity();
long length = entity.getContentLength();
InputStream is = entity.getContent();
FileOutputStream fileOutputStream = null;
if (is != null) {
File file = new File(
Environment.getExternalStorageDirectory(),
fileName);
fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[1024];
int ch = -1;
int count = 0;
while ((ch = is.read(buf)) != -1) {
// baos.write(buf, 0, ch);
fileOutputStream.write(buf, 0, ch);
count += ch;
}
}
fileOutputStream.flush();
if (fileOutputStream != null) {
fileOutputStream.close();
}
if (is != null) {
is.close();
}
}
HttpClient client = new DefaultHttpClient();
// params[0]代表连接的url
HttpGet get = new HttpGet(path);
HttpResponse response;
response = client.execute(get);
HttpEntity entity = response.getEntity();
long length = entity.getContentLength();
InputStream is = entity.getContent();
FileOutputStream fileOutputStream = null;
if (is != null) {
File file = new File(
Environment.getExternalStorageDirectory(),
fileName);
fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[1024];
int ch = -1;
int count = 0;
while ((ch = is.read(buf)) != -1) {
// baos.write(buf, 0, ch);
fileOutputStream.write(buf, 0, ch);
count += ch;
}
}
fileOutputStream.flush();
if (fileOutputStream != null) {
fileOutputStream.close();
}
if (is != null) {
is.close();
}
}
0 0
- 安卓下载保存到本地(一)
- 安卓下载保存到本地(二)
- 安卓网上下载 到本地保存 使用框架Retrofit
- Android安卓根据地址下载文件并保存到本地(HttpDownload)
- 下载视频文件保存到本地
- php 下载保存文件保存到本地
- 安卓调用系统摄像头拍照并保存到本地
- Java 下载 HTTP 资源保存到本地
- Android 下载网络图片保存到本地
- PHP 下载保存文件到本地
- nodejs下载图片保存到本地
- Android 下载网络图片保存到本地
- 保存内容到本地(下载到本地)
- 安卓adb-截图/录屏命令,保存到SD卡,导出到本地
- Android 保存文件到本地(一)
- android-安卓图片的缩放,以及下载保存如本地。
- 版本更新 下载APK asynctask下载文件 保存到本地
- 安卓实现从互联网上获取图片并保存到本地目录中
- 如何查看网站的访问量?查看访问量的二个主要方法【站长之家的SEO综合查询工具】
- exit(0)与exit(1)、return区别
- Step into Scala - 01 - 安装与运行
- OJ 删数问题
- 计算机网络基础
- 安卓下载保存到本地(一)
- Redis双向链表浅析
- [libevent]event,event_base结构体描述
- Android开发之Intent.Action
- 微信开发学习日记(六):weiphp框架
- PHP在kindeditor编辑器下内容不能提交的问题的解决方法
- ExpandableListView:展开新分组,自动关闭旧分组
- Step into Scala - 02 - 数据类型
- 在写德州扑克AI的时候想到的一种实现模糊决策的方法