使⽤java原⽣API模拟请求下载⽂件 1/**
2    *
sqrt数学上是什么意思3    * @param urlPath
4    *            下载路径
5    * @param saveDir
6    *            下载存放⽬录
7    * @return返回下载⽂件
8    * @throws Exception
9*/
10public static void downloadFile(String urlPath, String saveDir) throws Exception {
11        URL url = new URL(urlPath);
12// 连接类的⽗类,抽象类
java下载过程13        URLConnection urlConnection = url.openConnection();
14// http的连接类
15        HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
16// 设定请求的⽅法,默认是GETios空白代码2020
17        httpURLConnection.setRequestMethod("GET");
18// 设置字符编码
19        httpURLConnection.setRequestProperty("Charset", "UTF-8");
20//状态码 200:成功连接
21int code = ResponseCode();
22if (code == 200) {
23            System.out.println("链接地址成功!");
24        }
25        InputStream inputStream = InputStream();
26        File file = new File(saveDir);
phpadmin27        OutputStream out = new FileOutputStream(file);
全局钩子dll注入28int size = 0;
29byte[] buf = new byte[1024];
30while ((size = ad(buf)) != -1) {
31            out.write(buf, 0, size);
32        }
33        inputStream.close();
web前端开发培训学校
34        out.close();
35    }