集册 Java实例教程 获取InetAddress和默认字符集名称

获取InetAddress和默认字符集名称

欢马劈雪     最近更新时间:2020-01-02 10:19:05

486
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取InetAddress和默认字符集名称


//package com.nowjava;

import java.net.InetAddress;/*N o w  J a v a  . c o m 提 供*/

import java.net.UnknownHostException;

import java.nio.charset.Charset;

import java.util.Arrays;


public class Main {

    public static void main(String[] argv) throws Exception {

        getAddress();

    }


    public static void getAddress() throws UnknownHostException {


        String defaultCharsetName = Charset.defaultCharset().displayName();

        System.out.println("defaultCharsetName:" + defaultCharsetName);


        InetAddress address = InetAddress.getLocalHost();

        System.out.println(address.getHostName());

        System.out.println(address.getHostAddress());
        /*
         from n o w j a   v  a
展开阅读全文