import java.io.IOException;
public class Calc {
public static void main(String[] args) {
String osName = System.getProperty("os.name");
System.out.println(osName);
StringBuffer systempathBuff = new StringBuffer("");
if (osName.indexOf("Windows") > -1) {
systempathBuff.append("c:\\WINDOWS\\system32\\cmd.exe");
} else if (osName.indexOf("NT") > -1) {
systempathBuff.append("c:\\WINDOWS\\command.exe");
}
String[] cmd = new String[2];
cmd[0] = systempathBuff.toString();
cmd[1] = "/c calc.exe";// 计算器的绝对路径
System.out.println(cmd);
try {
@SuppressWarnings("unused")
Process p = Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}
}
}
使用Java实现Windows自带计算器(超简单)
最新推荐文章于 2022-03-22 21:25:01 发布