Getting the Computer Name in Java

Ant has always had a little hack for trying to get the computer name because it apparently doesn’t come natively. I thought that this was simply because Java didn’t have it available. Today I found that was wrong and stumbled across this little gem today, trying to do it programatically, and even though it’s not a system property, it still works like a charm.

InetAddress.getLocalHost().getHostName()

One Reply to “Getting the Computer Name in Java”

Comments are closed.