URL url = new URL(urlString);
File tempFile = null;
tempFile = File.createTempFile("cache", ".tmp", new File(Environment.getExternalStorageDirectory().toString()));
boolean downloaded = DownloadUtils.requestDownload(url, tempFile);
public class DownloadUtils {
private static final String TAG = "DownloadService";
public static boolean requestDownload(URL url, File file) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
return download(url, fos);
} catch (Throwable t) {
return false;
} finally {
Utils.closeSilently(fos);
}
}
public static void dump(InputStream is, OutputStream os)
throws IOException {
byte buffer[] = new byte[4096];
int rc = is.read(buffer, 0, buffer.length);
final Thread thread = Thread.currentThread();
w
Android: 通过URL下载文件
最新推荐文章于 2023-08-11 11:05:12 发布