Detecting Windows or Linux? [duplicate]
问题 This question already has answers here : How do I programmatically determine operating system in Java? (20 answers) Closed 4 years ago . 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? 回答1: apache commons lang has a class SystemUtils.java you can use : SystemUtils.IS_OS_LINUX SystemUtils.IS_OS_WINDOWS 回答2: Try: System