Java的osexecute_操作系统-Windows 10的Java的“ os.name”?

您也可以使用.contains(String)方法,仅检查“ windows”字符串可能遵循

if (System.getProperty("os.name").toLowerCase().contains("windows") && System.getProperty("os.name").toLowerCase().contains(windows version here [xp, 7, 8, etc]))){}

如果您需要Windows版本,则可以检查所有版本,然后假定8.1或10可以解决该错误。

if (System.getProperty("os.name").toLowerCase().contains("windows") && System.getProperty("os.name").toLowerCase().contains("xp")){

//code for windows xp }

else if (System.getProperty("os.name").toLowerCase().contains("windows") && System.getProperty("os.name").toLowerCase().contains("vista")){

//code for windows vista

else if (System.getProperty("os.name").toLowerCase().contains("windows") && System.getProperty("os.name").toLowerCase().contains("7")){

//code for windows 7}

else if (System.getProperty("os.name").toLowerCase().contains("windows") && System.getProperty("os.name").toLowerCase().contains("8")){

//code for windows 8}

else if (System.getProperty("os.name").toLowerCase().contains("windows") && System.getProperty("os.name").toLowerCase().contains("8.1")){

//code for both windows 8.1 and 10

}

现在解释一下这里发生了什么:

if语句只是确定Windows版本的条件

.contains(String)以字符串形式返回os的名称

.contains(String)方法使返回的String小写

.contains(String)方法检查给定的输入字符串是否包含在正在调用的字符串中

最后一条语句允许每个操作系统使用不同的代码,但8.1和10除外,这需要作为一个块来处理:(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值