How can I detect a Unix-like OS in Java?

Use the org.apache.commons.lang.SystemUtils utility class from Commons Lang, it has a nice IS_OS_UNIX constant. From the javadoc:

Is true if this is a POSIX compilant
system, as in any of AIX, HP-UX, Irix,
Linux, MacOSX, Solaris or SUN OS.

The field will return false if OS_NAME
is null.

And the test becomes:

if (SystemUtils.IS_OS_UNIX) {
    ...
}

Simple, effective, easy to read, no cryptic tricks.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)