栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

网络编程相关知识点

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

网络编程相关知识点

127.0.0.1代表本机(localhost)
查询ip地址的几种方法:

//查询本地地址
InetAddress byName = InetAddress.getByName(“127.0.0.1”);
InetAddress byname1 = InetAddress.getByName(“localhost”);
InetAddress byname2 = InetAddress.getLocalHost();//本机ip地址
InetAddress byName1 = InetAddress.getByName(“www.baidu.com”);

InetAddress与InetSocketAddress两种方法,了解即可。


socket在网络编程属于插槽,

tcp连接案例

可以下载网络资源代码:

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class download {
public static void main(String[] args) throws Exception {
//1.下载地址
URL url = new URL(“https://m701.music.126.net/20220105133033/424a7d447098f13bf603a04eace181a8/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/12380906077/95e1/9fe4/370a/e82ad1fd8281f85f551f29a5a8000c82.m4a”);
//2.连接到这个资源 http
URLConnection urlConnection = url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fos = new FileOutputStream(“c6.m4a”);
byte[] buffer = new byte[1024];
int len;
while((len=inputStream.read(buffer))!=-1){
fos.write(buffer,0,len);
}
}
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/697062.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号