标签:Java 编程 网络 System inet2 println InetAddress getByName out
在Java中使用InetAddress类代表IP
实例化InetAddress:两个方法:getByName(String host) 、 getLocalHost()两个常用方法:getHostName() / getHostAddress()
<code>try { //File file = new File("hello.txt"); InetAddress inet1 = InetAddress.getByName("192.168.10.14"); System.out.println(inet1); InetAddress inet2 = InetAddress.getByName("www.atguigu.com"); System.out.println(inet2); InetAddress inet3 = InetAddress.getByName("127.0.0.1"); System.out.println(inet3); //获取本地ip InetAddress inet4 = InetAddress.getLocalHost(); System.out.println(inet4); //getHostName() System.out.println(inet2.getHostName()); //getHostAddress() System.out.println(inet2.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); }
套接字封装类Socket
<code>
标签:Java,编程,网络,System,inet2,println,InetAddress,getByName,out
来源: https://www.cnblogs.com/jay-home/p/16350352.html