public class HttpDownloader extends Object
GET请求,默认支持30x跳转| Constructor and Description |
|---|
HttpDownloader() |
| Modifier and Type | Method and Description |
|---|---|
static long |
download(String url,
OutputStream out,
boolean isCloseOut,
StreamProgress streamProgress)
下载远程文件
|
static byte[] |
downloadBytes(String url)
下载远程文件数据,支持30x跳转
|
static byte[] |
downloadBytes(String url,
int timeout)
下载远程文件数据,支持30x跳转
|
static long |
downloadFile(String url,
File targetFileOrDir,
int timeout,
StreamProgress streamProgress)
下载远程文件
|
static long |
downloadFile(String url,
File targetFileOrDir,
String tempFileSuffix,
int timeout,
StreamProgress streamProgress)
下载文件-避免未完成的文件
来自:https://gitee.com/chinabugotech/hutool/pulls/407 此方法原理是先在目标文件同级目录下创建临时文件,下载之,等下载完毕后重命名,避免因下载错误导致的文件不完整。 |
static File |
downloadForFile(String url,
File targetFileOrDir,
int timeout,
StreamProgress streamProgress)
下载远程文件,返回文件
|
static String |
downloadString(String url,
Charset customCharset,
StreamProgress streamPress)
下载远程文本
|
public static String downloadString(String url, Charset customCharset, StreamProgress streamPress)
url - 请求的urlcustomCharset - 自定义的字符集,可以使用CharsetUtil#charset 方法转换streamPress - 进度条 StreamProgresspublic static byte[] downloadBytes(String url)
url - 请求的urlpublic static byte[] downloadBytes(String url, int timeout)
url - 请求的urltimeout - 超时毫秒数public static long downloadFile(String url, File targetFileOrDir, int timeout, StreamProgress streamProgress)
url - 请求的urltargetFileOrDir - 目标文件或目录,当为目录时,取URL中的文件名,取不到使用编码后的URL做为文件名timeout - 超时,单位毫秒,-1表示默认超时streamProgress - 进度条public static long downloadFile(String url, File targetFileOrDir, String tempFileSuffix, int timeout, StreamProgress streamProgress)
url - 请求的urltargetFileOrDir - 目标文件或目录,当为目录时,取URL中的文件名,取不到使用编码后的URL做为文件名tempFileSuffix - 临时文件后缀,默认".temp"timeout - 超时,单位毫秒,-1表示默认超时streamProgress - 进度条public static File downloadForFile(String url, File targetFileOrDir, int timeout, StreamProgress streamProgress)
url - 请求的urltargetFileOrDir - 目标文件或目录,当为目录时,取URL中的文件名,取不到使用编码后的URL做为文件名timeout - 超时,单位毫秒,-1表示默认超时streamProgress - 进度条public static long download(String url, OutputStream out, boolean isCloseOut, StreamProgress streamProgress)
url - 请求的urlout - 将下载内容写到输出流中 OutputStreamisCloseOut - 是否关闭输出流streamProgress - 进度条Copyright © 2025. All rights reserved.