将字符串“”localhost:8080“”转为SocketAddress

mmdee 发布于 2018/08/18 12:33
阅读 398
收藏 0

怎么将字符串“”localhost:8080“”转为SocketAddress?

加载中
0
0
蓝水晶飞机
蓝水晶飞机

看看JDK API 文档里面的java.net 你就知道怎么做啦:

URI uri = new java.net.URI("localhost:8080");
String host = uri.getHost();
int port = uri.getPort();
InetSocketAddress isa = new java.net.InetSocketAddress(host, port);

 

0
海上小岛
URI uri = new java.net.URI("http://localhost:8080");
String host = uri.getHost();
int port = uri.getPort();
InetSocketAddress isa = new java.net.InetSocketAddress(host, port);
0
k
kenneth123

new  InetSocketAddress(ip,port);

返回顶部
顶部