get Host Address Of Byte array - Java Network

Java examples for Network:Network Address

Description

get Host Address Of Byte array

Demo Code


//package com.java2s;

public class Main {

    /**/*from www .  ja v a  2 s .  c o m*/
     * 
     * @param bytes
     * @return host address,ex: 192.168.1.222
     */
    public static String getHostAddressOfBytes(byte[] bytes) {
        StringBuilder hostAddressBuilder = new StringBuilder();
        for (int i = bytes.length - 1; i >= 0; i--) {
            hostAddressBuilder.append("."
                    + Integer.toString(bytes[i] & 0xff));
        }
        return hostAddressBuilder.substring(1);
    }
}

Related Tutorials