📄 inetaddressexample.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -