Creating InetAddress object in Java
I am trying to convert an address specified by an IP number or a name, both in String (i.e. localhost
or 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)
Creating InetAddress object in Java的更多相关文章
- Creating default object from empty value in PHP?
Your new environment may have E_STRICT warnings enabled in error_reporting if it is PHP <= 5.3, ...
- hp警告Creating default object from empty value 问题的解决方法
hp警告Creating default object from empty value 问题的解决方法 解决方法是找到报错的位置然后看哪个变量是没有初始化而直接使用的,将这个变量先实例化一个空类.如 ...
- Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: 不支持的特性
mybatis插入数据时报错: Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or ...
- Wordpress里提示警告信息creating default object from empty value in *** 的解决方法
PHP里提示 Creating default object from empty value 的问题,一般是由于PHP版升级的原因,PHP 5.4 以上的版本一般会报这个错误.PHP的解决方法:找到 ...
- List<Map<String,Object>>使用Java代码遍历
List<Map<String,Object>>的结果集怎么使用Java代码遍历以获取String,Object的值: package excel; import java.u ...
- Object in Java same as pointer
到目前为止,读者应对对象的“传递”有了一个较为深刻的认识,记住实际传递的只是一个句柄. 然而准确地说,Java是有指针的!事实上,Java中每个对象(除基本数据类型以外)的标识符都属于指针的一种.但它 ...
- 开发工具、Object类(java基础知识十一)
1.常见开发工具介绍 * A:操作系统自带的记事本软件 * B:高级记事本软件 * C:集成开发环境 IDE * (Integrated Development Environment) * ...
- 包装类、Object类——Java笔记(八)
包装类: 基本数据类型的包装类 基本数据类型 包装类 byte Byte short Short int Integer long Long char Character float ...
- Object类-----java
Object类是所有类的父类,如果一个类没有使用extends关键字明确标识继承另一个类,那么这类默认继承object类 Object类中的方法,适合所有子类. 1 toString()方法在Obje ...
随机推荐
- C# WinForm给Button按钮或其它控件添加快捷键响应
就在这介绍三种添加快捷键的方式. 第一种Alt + *(按钮快捷键) 在大家给button.label.menuStrip等控件设置Text属性时在名字后边加&键名就可以了,比如button1 ...
- const和define的使用区别
在PHP中(PHP 4及以后),我们可以使用函数define()来定义常量,例如: <?php define('PI',3.14159); //定义一个名为PI的常量 echo PI; ...
- C语言之程序结构
一个好的程序首先要有好的程序结构,我从变量和结构两个方面来做分析. 一.浅谈程序中的变量 一个程序架构最基本的就是程序变量,谈到程序中的变量,我们应该考虑两部分,一方面是变量的作用域,一方面是变量的生 ...
- Spring实战——无需一行xml配置实现自动化注入
已经想不起来上一次买技术相关的书是什么时候了,一直以来都习惯性的下载一份电子档看看.显然,如果不是基于强烈的需求或强大的动力鞭策下,大部分的书籍也都只是蜻蜓点水,浮光掠影. 就像有位同事说的一样,有些 ...
- jquery点击图片选中特效
jquery点击图片选中特效 点击在线预览效果
- C++的类和对象
#include <iostream> // 预处理命令 using namespace std; class Student{ // 声明一个类,类名为Student private : ...
- python多线程 批量下补丁
一个一个下载 要2个多小时.就直接起了个线程池.效果明显.import urllib2 from urlparse import urlparse uri = 'http://******/patch ...
- Keys of HashMap in Java
The tricky thing is how to decide the key for a hashmap. Especially when you intend to use self-defi ...
- Why longest path problem doesn't have optimal substructure?
We all know that the shortest path problem has optimal substructure. The reasoning is like below: Su ...
- [wikioi]没有上司的舞会
树形DP.用F[k][0]和F[k][1]表示某节点不选和选了之后子树的最大值.那么:f[i][0]=sigma(max(f[k][0],f[k][1]))f[i][1]=sigma(f[k][0]) ...