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?
Click the "Start" button if there is one. A Microsoft Windows logo or flag may mean you have a version of Windows that predates Windows 95, such as Windows 3.11. If you see a red hat in a corner of your screen, you are running the Red Hat Linux operating system.
Use the System. getProperty() method in Java to get the Operating System name.
h> int uname(struct utsname *name);
apache commons lang has a class SystemUtils.java you can use :
SystemUtils.IS_OS_LINUX SystemUtils.IS_OS_WINDOWS
Try:
System.getProperty("os.name");
http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties%28%29
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With