宋子宪博客

使用Hutool 工具类实现远程文件下载

public class HttpDemo {

    public static void main(String[] args) {
            
        // 拼接url https://www.songzixian.com:8080/aaa/bbb?ie=UTF-8&wd=test
        String url = UrlBuilder.create()
                .setScheme("https")
                .setHost("www.hutool.cn")
                .setPort(8080)
                .addPath("/aaa").addPath("bbb")
                .addQuery("ie", "UTF-8")
                .addQuery("wd", "test")
                .build();
                
        // 下载保存到本地"D:\\tmp\\centre.xlsx
        long file = HttpUtil.downloadFile(url, "D:\\tmp\\centre.xlsx");

    }
}

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »