Search code examples
netbeansnetbeans-platform

how to detect OS at run time using java class?


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.


Solution

  • 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).