0

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.

user840930
  • 5,214
  • 21
  • 65
  • 94

2 Answers2

6

You can get the os type using

System.getProperty("os.name")
Siva
  • 1,938
  • 1
  • 17
  • 36
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
}
Community
  • 1
  • 1
Sven
  • 303
  • 2
  • 12