通过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(":");