get InetAddress and default Charset Name - Java Network

Java examples for Network:Network Address

Description

get InetAddress and default Charset Name

Demo Code


//package com.java2s;
import java.net.InetAddress;
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();/*from   ww  w.  j av  a  2 s .co m*/
    }

    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());
        byte[] bytes = address.getAddress();//byte????8?bit
        System.out.println(Arrays.toString(bytes));

    }
}

Related Tutorials