android怎么从服务器的一个存放图片的文件夹中下载其中所有的图片,已知文件夹的url
只要这个url和图片信息(比如名字)能组成有效的url就行了,然后再返回一个图片的名字列表,遍历下载就行了
考慮安裝一下 "抓圖神器" 這個APP
應該就可以解決你想下載圖片的問題!!
希望對你有幫助!!
试一下这个:
/**
* 下载文件线程
*
* @author coolszy
* @date 2012-4-26
* @blog http://blog.92coding.com
*/
private class downloadApkThread extends Thread {
@Override
public void run() {
try {
// 判断SD卡是否存在,并且是否具有读写权限
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
// 获得存储卡的路径
String sdpath = Environment.getExternalStorageDirectory() + "/";
mSavePath = sdpath + "download";
URL url = new URL(downUrl);
// 创建连接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
// 获取文件大小
int length = conn.getContentLength();
// 创建输入流
InputStream is = conn.getInputStream();
File file = new File(mSavePath);
// 判断文件目录是否存在
if (!file.exists()) {
file.mkdir();
}
File apkFile = new File(mSavePath, mAppName);
FileOutputStream fos = new FileOutputStream(apkFile);
int count = 0;
// 缓存
byte buf[] = new byte[1024];
// 写入到文件中
do {
int numread = is.read(buf);
count += numread;
// 计算进度条位置
progress = (int) (((float) count / length) * 100);
Message msg = new Message();
msg.obj = progress + "%";
msg.what = DOWNLOAD;
// 更新进度
mHandler.sendMessage(msg);
if (numread <= 0) {
// 下载完成
mDialog.cancel();
mHandler.sendEmptyMessage(DOWNLOAD_FINISH);
break;
}
// 写入文件
fos.write(buf, 0, numread);
} while (!cancelUpdate);// 点击取消就停止下载.
fos.close();
is.close();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// 取消下载对话框显示
if (downloadProgress != null ) {
downloadProgress.dismiss();
}
}
};