当前位置:网站首页>Use of URL download resources
Use of URL download resources
2022-07-26 14:11:00 【Look at the bugs】
##URL Use
package UdpCommuncation;
import java.net.MalformedURLException;
import java.net.URL;
public class TestURL {
public static void main(String[] args) throws MalformedURLException {
URL url=new URL("http://localhost:8080/helloworld/index.jsp?useername=yan=123");
System.out.println(url.getProtocol()); // agreement
System.out.println(url.getHost()); // host ip
System.out.println(url.getPort());// port
System.out.println(url.getPath());// route
System.out.println(url.getFile());// file
System.out.println(url.getQuery());// Parameters
}
}
Use URL Download resources
Need to open Tomcat
package UdpCommuncation;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class Down {
public static void main(String[] args) throws IOException {
//1, Download address
URL url=new URL("https://m704.music.126.net/20220725150910/04899645bb2ebc8ef5dbf6bcb1e07814/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/15384022047/73a2/a864/8dbb/1bdbc100f5143a96c0c34c5698e61732.m4a?authSecret=00000182341951661b4b0aaba0c8b0c8");
//2, Connect to this resource HTTP
HttpURLConnection urlConnection=(HttpURLConnection) url.openConnection();
InputStream inputStream=urlConnection.getInputStream();
FileOutputStream fos = new FileOutputStream("mi.m4a");
byte[] buffer = new byte[1024];
int len;
while((len=inputStream.read(buffer))!=-1){
fos.write(buffer,0,len);
}
fos.close();
inputStream.close();
urlConnection.disconnect();// disconnect
}
}
边栏推荐
- POM文件详解
- Research on technology subject division method based on patent multi-attribute fusion
- Jzoffer (array; string; linked list)
- 1-to-1 live broadcast source code - 1-to-1 voice chat source code
- 『BaGet』带你一分钟搭建自己的私有NuGet服务器
- Pytoch learning notes (II) the use of neural networks
- Prediction and value evaluation of technology fusion relationship based on multiple features
- MySQL-04 存储引擎和数据类型
- JS submit the form to determine whether the user name and password are empty
- How to quickly design a set of cross end components that support rendering rich text content
猜你喜欢

基于SPO语义三元组的疾病知识发现

JS get the current time, time and timestamp conversion

@千行百业,一起乘云而上!

Prediction and value evaluation of technology fusion relationship based on multiple features

「中高级试题」:MVCC实现原理是什么?

Docker integrates the redis sentinel mode (one master, two slave and three sentinels)

PHP uses sqlserver

低功耗多通道WFAS1431无线数据采集采发仪使用流程说明

Mlx90640 infrared thermal imager temperature sensor module development notes (6)

多态案例-制作饮品
随机推荐
Redis data operation
Learning basic knowledge of Android security
C语言_结构体指针变量引入
Plato farm is expected to further expand its ecosystem through elephant swap
JSON data returned by controller
Mobile dual finger scaling event (native), e.originalevent.touches
IDEA(warning)No artifacts configured
Redis的数据操作
『云原生』KubeSphere可插拔组件之DevOps系统
万字长文,浅谈企业数字化建模蓝图
大脑带来的启发:深度神经网络优化中突触整合原理介绍
ISCC2021 LOCKK题解
Synchronization mechanism of go (sync.mutex)
Jzoffer (array; string; linked list)
JS, e.pagex, pagey modal box drag
『BaGet』带你一分钟搭建自己的私有NuGet服务器
1对1直播源码——1对1语音聊天源码
Share 44 JS problems, and half of them are masters
JS download files, filesaver.js export txt and Excel files
What is restful style and its four specific implementation forms