需要获得本机名,经过调查得到两种方法:
String hostname = System.getProperty("user.name");String hostname = InetAddress.getLocalHost().getHostName();两种方法的区别是后一种得到字符串比第一种多一个“p-”请问这两种方法的区别,谢谢

解决方案 »

  1.   

    public static void main(String[] args) {
        // Untitled1 untitled1 = new Untitled1();
        System.out.println(System.getProperty("user.name"));    try {
          System.out.println(InetAddress.getLocalHost().getHostName());
        }
        catch (UnknownHostException ex) {
        }不会吧,前面一个当前登录系统的用户名,后一个是电脑的机器名,至于你多一个p-,去你的机器名的设置里面看看。