inetaddressexample.java

来自「java 完全探索的随书源码」· Java 代码 · 共 44 行

JAVA
44
字号
import java.net.*;public class InetAddressExample{  // Default Constructor  public InetAddressExample()  {    super();  }  public void doExample()  {    try    {      // Use the getByName method      System.out.print( "Using getByName(): " );      System.out.println( InetAddress.getByName( "www.sun.com" ) );      // Use the getAllByName method      // We'll use this host because they have several IP's for this hostname      System.out.println( "Using getAllByName()" );      InetAddress[] addresses = InetAddress.getAllByName( "www.microsoft.com" );      int size = addresses.length;      for( int i = 0; i < size; i++ )      {        System.out.println( addresses[i] );      }      // Use the get LocalHost method      System.out.print( "Using getLocalHost(): " );      System.out.println( InetAddress.getLocalHost() );    }    catch( UnknownHostException ex )    {      ex.printStackTrace();    }  }  public static void main(String[] args)  {    InetAddressExample example = new InetAddressExample();    example.doExample();  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?