如何将String类型的IP地址转化为InetAddress类型

如题所述

import java.net.*;
 
public class MyInetAddress1{
    public static void main(String[] args) throws Exception{
        //getLocalHost()
        InetAddress localAddress= InetAddress.getLocalHost();
        String local= localAddress.toString();
        String temp[]= local.split("/");
        System.out.println("getLocalHost()");
        System.out.println("主机名: "+temp[0]);
        System.out.println("IP地址:"+temp[1]);
        //System.out.println(localAddress);
    }
}
温馨提示:答案为网友推荐,仅供参考