Detecting Windows or Linux?

Ron Whites picture Ron Whites · Jan 12, 2013 · Viewed 114.6k times · Source

I am seeking to run a common Java program in both Windows and Linux.

The program needs to do some things differently on each platform.

So how can / should my Java program detect it is running under Linux vs. Windows?

Answer

othman picture othman · Jan 12, 2013

apache commons lang has a class SystemUtils.java you can use :

SystemUtils.IS_OS_LINUX
SystemUtils.IS_OS_WINDOWS