General discussion

  • Creator
    Topic
  • #3988374

    How do I programmatically determine operating system in Java?

    by pipes-pigeon0l ·

    Tags: 

    I would like to determine the operating system of the host that my Java program is running programmatically (for example: I would like to be able to load different properties based on whether I am on a Windows or Unix platform). What is the safest way to do this with 100% reliability?

You are posting a reply to: How do I programmatically determine operating system in Java?

The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our Community FAQs for details. All submitted content is subject to our Terms of Use.

All Comments

  • Author
    Replies
    • #3988375

      Re: determine host operating system in Java

      by kees_b ·

      In reply to How do I programmatically determine operating system in Java?

    • #3988559

      Reply To: How do I programmatically determine operating system in Java?

      by jinesh.sethia ·

      In reply to How do I programmatically determine operating system in Java?

      class TestJava { public static void main (String[] args) { String operatingSystem = System. getProperty(“os.name”). toLowerCase(); if (operatingSystem. contains(“win”)){ System. out. println(“Operating system is Windows”); } else if (operatingSystem. contains(“osx”)){ System. out. println(“Operating system is OSX”); } else if (operatingSystem. contains(“nix”)){ System. out. println(“Operating system is NIX”); } else if (operatingSystem. contains(“nux”)){ System. out. println(“Operating system is NUX”); } else if (operatingSystem. contains(“aix”)){ System. out. println(“Operating system is *AIX”); } } }

Viewing 1 reply thread