-2

Is it possible to check the current Operating System with Java? I want my program to do something different on Linux.

Something like that

if(os == Linux) {

...

}

Tailor
  • 193
  • 1
  • 12
  • 1
    You really should at the very least search this site for your question, if not search google first. When you search "java get operating system" the answer is one of the first results (plus you will want to search the site for properly comparing strings. Hint is that it's not done with the `==` operator). – scrappedcola Mar 31 '18 at 22:02
  • check this answer, https://stackoverflow.com/a/36926327/4042213 , it will give you the possible values. – Ebraheem Alrabeea Mar 31 '18 at 22:20

1 Answers1

1

Try this:

System.getProperty("os.name")

For example:

if("Linux".equals(System.getProperty("os.name"))) {
    System.out.println("This is Linux");
}
  • Thanks it worked. If I want to check if the os is mac, do I have to change "Linux" to "Mac" ? – Tailor Apr 01 '18 at 12:57