Which of the following is the best and most portable way to get the hostname of the current computer in Java?

Runtime.getRuntime().exec("hostname")

vs

InetAddress.getLocalHost().getHostName()

11 Answers
11

Leave a Reply

Your email address will not be published. Required fields are marked *