SystemUtils.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package org.springblade.common.utils;
  2. public class SystemUtils {
  3. /**
  4. * 判断操作系统是否是 Windows
  5. *
  6. * @return true:操作系统是 Windows
  7. * false:其它操作系统
  8. */
  9. public static boolean isWindows() {
  10. String osName = getOsName();
  11. return osName != null && osName.startsWith("Windows");
  12. }
  13. /**
  14. * 判断操作系统是否是 MacOS
  15. *
  16. * @return true:操作系统是 MacOS
  17. * false:其它操作系统
  18. */
  19. public static boolean isMacOs() {
  20. String osName = getOsName();
  21. return osName != null && osName.startsWith("Mac");
  22. }
  23. /**
  24. * 判断操作系统是否是 Linux
  25. *
  26. * @return true:操作系统是 Linux
  27. * false:其它操作系统
  28. */
  29. public static boolean isLinux() {
  30. String osName = getOsName();
  31. return (osName != null && osName.startsWith("Linux")) || (!isWindows() && !isMacOs());
  32. }
  33. /**
  34. * 获取操作系统名称
  35. *
  36. * @return os.name 属性值
  37. */
  38. public static String getOsName() {
  39. return System.getProperty("os.name");
  40. }
  41. }