2

I make modular App in netbeans platform, and I don't know how to check in which OS this App is running java? accoriding that I want to set the path of my folder and images in my App. and I want to check that at run time. Please suggest me.

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Jay
  • 1,235
  • 10
  • 28
  • 49
  • Check out this topic: How do I programmatically determine operating system in Java? http://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java – dexametason Apr 03 '12 at 06:38

5 Answers5

4

If you are using the NetBeans Platform then you should add a dependency with the Utilities module (very useful):

Then you just say

Utilities.isMac() or Utilities.isUnix() or Utilities.isWindows().

In case you want to do it more precisely you can

switch( Utilities.getOperatingSystem() )
{
  case Utilities.OS_AIX: 
  case Utilities.OS_FREEBSD:
  case Utilities.OS_HP:
  case Utilities.OS_IRIX:
  case Utilities.OS_LINUX:
  case Utilities.OS_MAC:
  case Utilities.OS_OPENBSD:
  case Utilities.OS_OS2:
  case Utilities.OS_SOLARIS:
  case Utilities.OS_SUNOS:
  case Utilities.OS_TRU64:
  case Utilities.OS_WIN95:
  case Utilities.OS_WIN98:
  case Utilities.OS_WIN2000:

(Well, and all the rest, this is getting too long for an answer, I'm afraid, see the link above for more OSes).

2

Through:

String osName = System.getProperty("os.name").toLowerCase();

You get Os name and you able to compare with your os.For example:

boolean isMacOs = osName.startsWith("mac os x"); 
if (isMacOs) 
{
  // do mac-specific things here
}
4b0
  • 21,981
  • 30
  • 95
  • 142
1

this method returns OS name as String

System.getProperty("os.name");

This class might be of use to start with

http://www.mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname/

Jayy
  • 2,368
  • 4
  • 24
  • 35
0

Use the System.getProperty("os.name").

npinti
  • 51,780
  • 5
  • 72
  • 96
0

System.getProperty("os.name"); should return the OS name.

Shashank Kadne
  • 7,993
  • 6
  • 41
  • 54