Get system hostname in java
package com.w3spoint;
import java.net.InetAddress;
public class NetworkingTest {
public static void main(String args[]){
try {
InetAddress myHost = InetAddress.getLocalHost();
System.out.println(myHost.getHostName());
} catch(Exception e) {
e.printStackTrace();
}
}
} |
package com.w3spoint; import java.net.InetAddress; public class NetworkingTest {
public static void main(String args[]){
try {
InetAddress myHost = InetAddress.getLocalHost();
System.out.println(myHost.getHostName());
} catch(Exception e) {
e.printStackTrace();
}
}
}
Output