关闭电脑 [英] Shutting down a computer

查看:105
本文介绍了关闭电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用内置的Java方法关闭计算机?

Is there a way to shutdown a computer using a built-in Java method?

推荐答案

创建自己的执行函数操作系统命令通过命令行

Create your own function to execute an OS command through the command line?

为了举个例子。但是知道你想要在其他地方使用它的地点和原因。

For the sake of an example. But know where and why you'd want to use this as others note.

public static void main(String arg[]) throws IOException{
    Runtime runtime = Runtime.getRuntime();
    Process proc = runtime.exec("shutdown -s -t 0");
    System.exit(0);
}

这篇关于关闭电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆