File tree Expand file tree Collapse file tree
src/main/java/com/mkyong/system Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222
2323 <dependencies >
2424
25+ <dependency >
26+ <groupId >org.apache.commons</groupId >
27+ <artifactId >commons-lang3</artifactId >
28+ <version >3.11</version >
29+ </dependency >
30+
2531 <dependency >
2632 <groupId >org.junit.jupiter</groupId >
2733 <artifactId >junit-jupiter-params</artifactId >
Original file line number Diff line number Diff line change 1+ package com .mkyong .system ;
2+
3+ public class OSValidator {
4+
5+ private static String OS = System .getProperty ("os.name" ).toLowerCase ();
6+ public static boolean IS_WINDOWS = (OS .indexOf ("win" ) >= 0 );
7+ public static boolean IS_MAC = (OS .indexOf ("mac" ) >= 0 );
8+ public static boolean IS_UNIX = (OS .indexOf ("nix" ) >= 0 || OS .indexOf ("nux" ) >= 0 || OS .indexOf ("aix" ) > 0 );
9+ public static boolean IS_SOLARIS = (OS .indexOf ("sunos" ) >= 0 );
10+
11+ public static void main (String [] args ) {
12+
13+ System .out .println ("os.name: " + OS );
14+
15+ if (IS_WINDOWS ) {
16+ System .out .println ("This is Windows" );
17+ } else if (IS_MAC ) {
18+ System .out .println ("This is Mac" );
19+ } else if (IS_UNIX ) {
20+ System .out .println ("This is Unix or Linux" );
21+ } else if (IS_SOLARIS ) {
22+ System .out .println ("This is Solaris" );
23+ } else {
24+ System .out .println ("Your OS is not support!!" );
25+ }
26+ }
27+
28+ }
You can’t perform that action at this time.
0 commit comments