Core API
How do I get a localhost hostname?
package org.kodejava.network; import java.net.InetAddress; import java.net.UnknownHostException; public class HostNameExample { public static void main(String[] args) { try { InetAddress address = InetAddress.getLocalHost(); System.out.println("Hostname: " + address.getHostName()); } catch (UnknownHostException e) { e.printStackTrace(); } } } An example of output produce by the code snippet above is: Hostname: Krakatau
Artikel oleh Wayan · Sumber: Kode Java ↗
Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.
package org.kodejava.network;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class HostNameExample {
public static void main(String[] args) {
try {
InetAddress address = InetAddress.getLocalHost();
System.out.println("Hostname: " + address.getHostName());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
An example of output produce by the code snippet above is:
Hostname: Krakatau
