当前位置:网站首页>URL to download network resources
URL to download network resources
2022-04-21 19:47:00 【Nameless`】
package com.wuming.lesson04;
import java.net.MalformedURLException;
import java.net.URL;
public class URLDemo01 {
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("http://localhost:8080/helloworld/index.jsp?username=wuming&password=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());// file
System.out.println(url.getFile());// The full path
System.out.println(url.getQuery());// Parameters
}
}
================
package com.wuming.lesson04;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class UrlDown {
public static void main(String[] args) throws Exception {
//1. Download address
URL url = new URL("https://p2.music.126.net/xOMA-0nOKNmweJ-vcfaBMQ==/109951167290093049.jpg?param=200y200");
//2. Connect to this resource HTTP
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fos = new FileOutputStream("109951167290093049.jpg");
byte[] buffer = new byte[1024];
int len;
while((len=inputStream.read(buffer))!=-1){
fos.write(buffer,0,len);// Write this data
}
fos.close();
inputStream.close();
urlConnection.disconnect();// disconnect
}
}
========
Download the pictures
Under the root directory path

Download Music , Play it on the player

版权声明
本文为[Nameless`]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211941124824.html
边栏推荐
- 配置PyTorch、TensorFlow 环境
- SAP PS section 12 network cost plan
- 静态链接与动态链接
- Why does SVPWM module have sector judgment error?
- 阿里IOT
- OpenHarmony Sensor 模块Callback注册和回调全流程
- Text to SQL learning and sorting (XVII) s2sql model
- Switch branch
- SAP PS 第12节 网络成本计划
- Overview of relational database and non relational database, introduction to redis, common commands and optimization
猜你喜欢

ROS知识:如何实现相机接入

2023年南开大学税务专硕考研上岸前辈备考经验指导

照片删除了怎么恢复?4个方案,这才是官方指南

有趣的灵魂千篇一律,电脑滑动关机,仅需2步

leetcode18. 四数之和

SAP PS section 12 network cost plan

Imea | endnote tutorial on adjusting perfect citation format (video)
![[netty] is it difficult to implement a redis client by yourself?](/img/02/a9609465d2cc90251168b2ed0b94f0.png)
[netty] is it difficult to implement a redis client by yourself?

数商云:剖析企业采购管理的现状,推进企业采购模式优化升级

Today's sleep quality record is 83 points
随机推荐
杰理之系统内核电压【篇】
野路子玩Qt,第三十一集,擦玻璃游戏
SVPWM模块为什么会出现扇区判断错误?
leetcode541. Reverse string II
居家第二十一天的成果
学完这篇Charles抓包教程,我直接把fiddler卸载了
Building / Qt 5 and QT 6 compatibility using cmake
Leetcode goat Latin [analog string] the way of leetcode in heroding
getchar,putchar,EOF
Results of the 21st day at home
Have you mastered the answers of PMP Exam?
MYSQL输入密码后闪退的解决方法
MySQL MHA high availability cluster deployment and failover
【2021】腾讯秋招技术岗编程 有效序列的数量
DolphinDB VSCode 插件使用教程
[maximum value of jz47 gift]
Leetcode0886. 可能的二分法(medium,二分图)
06.适配器模式
WLAN Qpower 介绍
学历造假、考试包过……考证市场有多乱