[Java]通过java获取计算机名

通过java获取计算机名

String hostname = "Unknown";

		try

		{

		    InetAddress addr;

		    addr = InetAddress.getLocalHost();

		    hostname = addr.getHostName();

		}

		catch (UnknownHostException ex)

		{

		    System.out.println("Hostname can not be resolved");

		}

		logger.info("The computer name is: " + hostname);

 

你可能感兴趣的:(java)