kotlin获取属性
The task is to get the system name.
任务是获取系统名称。
package com.includehelp
import java.net.InetAddress
/**
* Function for System Name
*/
fun getSystemName(): String? {
return try {
InetAddress.getLocalHost().hostName
} catch (E: Exception) {
System.err.println("System Name Exp : " + E.message)
null
}
}
//Main function , Program Entry Point
fun main(args: Array<String>) {
// Call Function to get Computer System Name
val systemName = getSystemName()
// Print Computer Name
println("Computer Name : $systemName")
}
Output
输出量
Computer Name : DESKTOP-16EO58R
翻译自: https://www.includehelp.com/kotlin/get-system-name.aspx
kotlin获取属性