Java Loopback Address Get getLoopbackAddress()

Here you can find the source of getLoopbackAddress()

Description

get Loopback Address

License

Apache License

Declaration

public static String getLoopbackAddress() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {
    public static String getLoopbackAddress() {
        // InetAddress.getLoopbackAddress() is @since 1.7
        //// www . ja  va  2s  .c o m
        // Aside from that, getLoopbackAddress() seems preferable to
        // InetAddress.getByName("localhost") since the former doesn't seem to
        // require the local resolver to be sane.
        //return InetAddress.getLoopbackAddress().getHostAddress();
        try {
            return InetAddress.getByName("localhost").getHostAddress();
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. getLoopBackAddress()
  2. getLoopbackAddress()