码迷,mamicode.com
首页 > 编程语言 > 详细

Java网络编程一

时间:2018-10-15 01:19:11      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:known   print   shm   spi   tac   inter   cti   auth   hashmap   

 

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网络编程一

标签:known   print   shm   spi   tac   inter   cti   auth   hashmap   

原文地址:https://www.cnblogs.com/Roni-i/p/9788983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!