Java: convert int to InetAddress

后端 未结 10 1203
既然无缘
既然无缘 2020-12-14 06:34

I have an int which contains an IP address in network byte order, which I would like to convert to an InetAddress object. I see that there is an <

10条回答
  •  隐瞒了意图╮
    2020-12-14 07:19

      public InetAddress intToInetAddress(Integer value) throws UnknownHostException
      {
        ByteBuffer buffer = ByteBuffer.allocate(32);
        buffer.putInt(value);
        buffer.position(0);
        byte[] bytes = new byte[4];
        buffer.get(bytes);
        return InetAddress.getByAddress(bytes);
      }
    

提交回复
热议问题