views:

192

answers:

4

I have a Java web app that I develop on a Windows machine and will deploy on a Unix machine.

There are some file path settings and permissions details that differ on the two (and there is nothing I can do to change this). Is there some way of detecting which machine the app is sitting on (it's only one of two), either by detecting the operating system or the computer's name so I can then using the appropriate settings.

+2  A: 

Check this: http://www.roseindia.net/java/beginners/OSInformation.shtml

ahmadabdolkader
More FAQ: http://www.codestyle.org/java/servlets/faq-HowTo.shtml#systemprops
ahmadabdolkader
+1  A: 

You can use System.getProperty("os.name")

Eyal Schneider
+3  A: 

You can use

java.lang.System.getProperty("os.name")

to know the operating system name.

Get more info at http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html

RaviG
+4  A: 

Computer name and OS name are two different properties to get computer name use

String computername=InetAddress.getLocalHost().getHostName();
      System.out.println(computername);

and to get os name use

java.lang.System.getProperty("os.name")

Abdul Khaliq

Abdul Khaliq
Thanks for both options.
Ankur