Skip to content

Commit 21f7223

Browse files
committed
detect os
1 parent 2728f48 commit 21f7223

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

java-basic/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
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>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)