Is there a way to tell in Java if the program is running on a Windows or Linux machine? I have a .jar file that I want to run on both.
Asked
Active
Viewed 1,618 times
0
-
1I'd be very surprised if this question hasn't been asked before. – Mitch Wheat Nov 23 '13 at 05:12
2 Answers
2
here you go,
How do I programmatically determine operating system in Java?
VonC's answer
public static final class OsUtils
{
private static String OS = null;
public static String getOsName()
{
if(OS == null) { OS = System.getProperty("os.name"); }
return OS;
}
public static boolean isWindows()
{
return getOsName().startsWith("Windows");
}
public static boolean isUnix() // and so on
}