Java网络编程一
Posted Roni
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java网络编程一相关的知识,希望对你有一定的参考价值。
1.InetAddress的应用
import java.util.List; import java.math.BigDecimal; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; import java.util.Stack; import javax.naming.spi.DirStateFactory.Result; import org.omg.PortableInterceptor.DISCARDING; import java.util.Map; import java.util.Queue; /** * InetAddress类 * @author 16114 * */ public class Main{ public static void main(String[] args) { try { InetAddress address = InetAddress.getLocalHost(); System.out.println("计算机名:" + address.getHostName()); System.out.println("IP地址:" + address.getHostAddress()); byte[] bytes = address.getAddress(); System.out.println("字节数组形式的IP:" + Arrays.toString(bytes)); System.out.println(address); } catch (UnknownHostException e) { e.printStackTrace(); } try { InetAddress address2 = InetAddress.getByName("Roni"); System.out.println(address2.getHostName()); System.out.println(address2.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); } } }
以上是关于Java网络编程一的主要内容,如果未能解决你的问题,请参考以下文章