怎样在JAVA取得计算机名
2个回答
展开全部
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Test {
public static void main(String[] args) {
try {
InetAddress inetAddress = InetAddress.getLocalHost();
System.out.println("本机IP:" + inetAddress.getHostAddress().toString());
System.out.println("本机名称:" + inetAddress.getHostName().toString());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询