package com.example.climbnumber;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.zip.GZIPInputStream;
public class Test02 {
public static void main(String[] args) {
try {
download("https://disclosure.shcpe.com.cn//cpec-ent/file/20220508/1652002109174%E6%88%AA%E8%87%B32022%E5%B9%B44%E6%9C%8830%E6%97%A5%E6%8C%81%E7%BB%AD%E9%80%BE%E6%9C%9F%E5%90%8D%E5%8D%95.pdf", "C:\\Users\\13560\\Desktop\\12.pdf");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void download(String urlString, String filename) throws Exception {
URL url = new URL(urlString);
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
String code = con.getHeaderField("Content-Encoding");
if ((null != code) && code.equals("gzip")) {
GZIPInputStream gis = new GZIPInputStream(is);
byte[] bs = new byte[1024];
int len;
OutputStream os = new FileOutputStream(filename);
while ((len = gis.read(bs)) != -1) {
os.write(bs, 0, len);
}
gis.close();
os.close();
is.close();
} else {
byte[] bs = new byte[1024];
int len;
OutputStream os = new FileOutputStream(filename);
while ((len = is.read(bs)) != -1) {
os.write(bs, 0, len);
}
os.close();
is.close();
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)