In kotlin also you can use System.getProperty("os.name") for detect type OS.
Check example class test.kt
fun main(args: Array<String>) {
val OS = System.getProperty("os.name").toLowerCase()
when {
OS.indexOf("win") >= 0 -> {
print("Windows")
}
OS.indexOf("mac") >= 0 -> {
print("Mac")
}
(OS.indexOf("nix") >= 0
|| OS.indexOf("nux") >= 0
|| OS.indexOf("aix") > 0) -> {
print("Unix or Linux")
}
OS.indexOf("sunos") >= 0 -> {
print("Solaris")
}
else -> print("Others")
}
}
References:
http://lopica.sourceforge.net/os.html
https://mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname
No comments:
Post a Comment