1.打开网易云,选择一首歌曲播放,然后按f12
2.找到并点击以.m4a
结尾的链接
3.把输入框的链接替换代码里面的URL
//1.获取资源地址
URL url = new URL("https://m801.music.126.net/20201006161345/802c3e2bd0240db619e27a7f1eeffcce/jdyyaac/5608/005a/075c/ab4dced2f970a635a1a406abeba63cf4.m4a");
4.然后更改一下输出名字f.m4a
,运行就ok了
5.java代码(其他资源也是类似,更改路径即可)
代码思路:
- 获取地址链接
- 连接资源
- 输出资源
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/**
* @author liu
* @Description
*/
public class URLdown {
public static void main(String[] args) throws Exception {
//1.获取资源地址
URL url = new URL("https://m801.music.126.net/20201006161345/802c3e2bd0240db619e27a7f1eeffcce/jdyyaac/5608/005a/075c/ab4dced2f970a635a1a406abeba63cf4.m4a");
//2.连接资源
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fos = new FileOutputStream("f.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();
}
}