-
-
System.out.println(System.getProperty ("user.name"));
-
That will just give you the username of that computer. I don't think, you can get the Systems name by using
System.getProperty(...), as the following code should display all possibilities, which (at least on my computer) do not include the Systems name.
-
if (args == null || args.length == 0)
-
{
-
java.util.Enumeration e = System.getProperties().propertyNames();
-
while (e.hasMoreElements()) {
-
String key = (String)e.nextElement();
-
System.out.println(key +"\t : \t"+ System.getProperty(key));
-
}
-
}
-
else
-
{
-
for (int n = 0; n < args.length; ++ n)
-
{
-
if (args[n] != null && args[n].length() > 0)
-
{
-
String p = System.getProperty(args[n]);
-
if (p != null)
-
System.out.println(p);
-
}
-
}
-
}
-
If you want the actual computers name, try this:
-
try {
-
java.net.InetAddress i = java.net.InetAddress.getLocalHost();
-
System.out.println(i); // name and IP address
-
System.out.println(i.getHostName()); // name
-
System.out.println(i.getHostAddress()); // IP address only
-
}
-
catch(Exception e){e.printStackTrace();}
-
Source:
http://www.rgagnon.com/javadetails/java-0390.html