集册 Java实例教程 通过InetSocketAddress解析主机和端口

通过InetSocketAddress解析主机和端口

欢马劈雪     最近更新时间:2020-01-02 10:19:05

487
通过InetSocketAddress解析主机和端口


//package com.nowjava;

import java.net.InetAddress;
/** 
 来自 nowjava.com - 时  代  Java**/

import java.net.InetSocketAddress;

import java.net.UnknownHostException;


public class Main {

    public static void main(String[] argv) throws Exception {

        String hostAndPort = "nowjava.com";

        System.out.println(parse(hostAndPort));

    }


    public static InetSocketAddress parse(String hostAndPort)

            throws UnknownHostException {/**from n o w    j a v a  . c o m**/

        String[] strings = hostAndPort.split(":");

        
展开阅读全文