Creating InetAddress object in Java
2014-10-21 03:13
603 查看
I am trying to convert an address specified by an IP number or a name, both in String (i.e.
You should be able to use getByName or getByAddress.
The host name can either be a machine name, such as "java.sun.com", or a textual representation of its IP address
The method that takes a byte array can be used like this:
localhostor
127.0.0.1), into an InetAdress object. There's no constructor but rather static methods that return an InetAddress. So if I get a host name it's not a problem, but what if I get the IP number? There's one method that getsbyte[] but I'm not sure how that can help me. All other methods gets the host name.
You should be able to use getByName or getByAddress.
The host name can either be a machine name, such as "java.sun.com", or a textual representation of its IP address
InetAddress addr = InetAddress.getByName("127.0.0.1");
The method that takes a byte array can be used like this:
byte[] ipAddr = new byte[]{127, 0, 0, 1}; InetAddress addr = InetAddress.getByAddress(ipAddr)
相关文章推荐
- InetAddress Example program in Java
- Creating MTS ActiveX Object in Java
- Process of creating an object in Java
- JSON详细学习之JSONObject in JAVA
- java.net.BindException: Address already in use: JVM_Bind:8080
- java.net.BindException: Address already in use: JVM_Bind
- Object-Oriented Design in Java
- java.net.BindException: Address already in use: JVM_Bind
- java.net.BindException: Address already in use解决方法
- java.net.BindException: Address already in use: JVM_Bind:8080 issue
- 80端口占用异常解决方法java.net.BindException: Address already in use: JVM_Bind:80(或8080)
- Thinking in Java 读书笔记 —— 1.Introducation to Object
- Build your own ObjectPool in Java to boost app speed
- 处理教材:Everything is an object of "Thinking in Java"
- 处理教材:Everything is an object of "Thinking in Java"
- 修改 Tomcat 端口 号 java.net.BindException: Address already in use: JVM_Bind:8080
- Get Mac Address in Java
- 奋斗了n(n>7)小时,终于解决了连接远程JMS JNDI的问题:java.rmi.NoSuchObjectException: no such object in table
- Tomcat 6.0 错误信息: 严重: StandardServer.await:create[8005]: java.net.BindException: Address already in use: JVM_Bind
- tomcat启动错误:java.net.BindException: Address already in use: JVM_Bind:8080