JAVA 获得IP地址
1. java 获取ip地址的代码
String loacalIp = "";
try
{
InetAddress localhost = InetAddress.getLocalHost();
loacalIp =localhost.getHostAddress();
//System.out.println("localhost: "+localhost.getHostAddress());
//System.out.println("localhost: "+localhost.getHostName());
}
catch(UnknownHostException uhe)
{
System.err.println("Localhost Ip exception " + uhe.toString());
}
A:此代码在windows 下面获取ip地址是完全正确。
B:此代码在linux下面取得的ip地址总是:127.0.0.1
2.为了获取linux下面正确的ip地址
修改etc下面的hosts文件
***.***.***.*** localhost.localdomain localhost
修改为本机的ip地址,而不是127.0.0.1
具体修改的方法,当然是用vi进行编辑。保存后不用重启机器,即可。
相关文档:
public class Test {
public static void main(String args[]) {
int i;
int j;
for (i = 1; i <= 9; i++) {
for (j = 1; j <= i; j++) {
if (j * i <= 9)
System.out.print(j ......
构造方法:
String()
初始化一个新创建的 String 对象,它表示一个空字符序列。
String(byte[] bytes)
构造一个新的 String,方法是使用平台的默认字符集解码字节的指定数组。
String(byte ......
java调用外部程序 必杀 路径空格没有问题
Runtime rt = Runtime.getRuntime();
srcFile.getName();
try {
String cmd[]={"cmd","/c",srcFile.getAbsolutePath()};
rt.exec(cmd);
} catch (IOException e1) {
// TODO Auto-genera ......
1、进程与线程:
《1》什么是进程:是指运行中的应用程序,每一个进程都有自己独立的内存空间,
一个应用程序可以同时启动多个进程,(静态)比如(IE,JVM)
《2》什么是线程:是指进程中的一个执行流程, ......
关于Jaybird-2.1.6JDK_1.5的使用方法如下:
首先:安装Jaybird
第一步:将根目录下的
jaybird21.dll,
GDS32.DLL,
icudt30.dll,
icuuc30.dll,
&nbs ......