import java.net.InetAddress;
import java.io.IOException;
/**
* Created by IntelliJ IDEA.
* User: 141
* Date: 2002-1-1
* Time: 8:06:58
* To change this template use File | Settings | File Templates.
*/
public class InetAddressTest {
void display(){
byte[]buf=new byte[100];
try{
System.out.println("输入主机名字:");
int count=System.in.read(buf);
String hostName=new String(buf,0,count-2);
InetAddress []addrs=new InetAddress.getAllByName(hostName);//此处出现问题。。
System.out.println();
System.out.println("主机"+addrs[0].getHostName()+"有如下IP地址");
for(int i=0;i<addrs.length;i++){
System.out.println(addrs[i].getHostAddress());
}
}catch(IOException e){System.out.println(e);}
}
public static void main(String args[]){
InetAddressTest app=new InetAddressTest();
app.display();
}
}
照着书上弄的,编译都通不过。
import java.io.IOException;
/**
* Created by IntelliJ IDEA.
* User: 141
* Date: 2002-1-1
* Time: 8:06:58
* To change this template use File | Settings | File Templates.
*/
public class InetAddressTest {
void display(){
byte[]buf=new byte[100];
try{
System.out.println("输入主机名字:");
int count=System.in.read(buf);
String hostName=new String(buf,0,count-2);
InetAddress []addrs=new InetAddress.getAllByName(hostName);//此处出现问题。。
System.out.println();
System.out.println("主机"+addrs[0].getHostName()+"有如下IP地址");
for(int i=0;i<addrs.length;i++){
System.out.println(addrs[i].getHostAddress());
}
}catch(IOException e){System.out.println(e);}
}
public static void main(String args[]){
InetAddressTest app=new InetAddressTest();
app.display();
}
}
照着书上弄的,编译都通不过。
把new去掉就可以了